~jsing/wordpress/openstack-objectstorage-revert

« back to all changes in this revision

Viewing changes to vendor/doctrine/instantiator/tests/DoctrineTest/InstantiatorTest/Exception/UnexpectedValueExceptionTest.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
14
 *
 
15
 * This software consists of voluntary contributions made by many individuals
 
16
 * and is licensed under the MIT license. For more information, see
 
17
 * <http://www.doctrine-project.org>.
 
18
 */
 
19
 
 
20
namespace DoctrineTest\InstantiatorTest\Exception;
 
21
 
 
22
use Doctrine\Instantiator\Exception\UnexpectedValueException;
 
23
use Exception;
 
24
use PHPUnit_Framework_TestCase;
 
25
use ReflectionClass;
 
26
 
 
27
/**
 
28
 * Tests for {@see \Doctrine\Instantiator\Exception\UnexpectedValueException}
 
29
 *
 
30
 * @author Marco Pivetta <ocramius@gmail.com>
 
31
 *
 
32
 * @covers \Doctrine\Instantiator\Exception\UnexpectedValueException
 
33
 */
 
34
class UnexpectedValueExceptionTest extends PHPUnit_Framework_TestCase
 
35
{
 
36
    public function testFromSerializationTriggeredException()
 
37
    {
 
38
        $reflectionClass = new ReflectionClass($this);
 
39
        $previous        = new Exception();
 
40
        $exception       = UnexpectedValueException::fromSerializationTriggeredException($reflectionClass, $previous);
 
41
 
 
42
        $this->assertInstanceOf('Doctrine\\Instantiator\\Exception\\UnexpectedValueException', $exception);
 
43
        $this->assertSame($previous, $exception->getPrevious());
 
44
        $this->assertSame(
 
45
            'An exception was raised while trying to instantiate an instance of "'
 
46
            . __CLASS__  . '" via un-serialization',
 
47
            $exception->getMessage()
 
48
        );
 
49
    }
 
50
 
 
51
    public function testFromUncleanUnSerialization()
 
52
    {
 
53
        $reflection = new ReflectionClass('DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset');
 
54
        $exception  = UnexpectedValueException::fromUncleanUnSerialization($reflection, 'foo', 123, 'bar', 456);
 
55
 
 
56
        $this->assertInstanceOf('Doctrine\\Instantiator\\Exception\\UnexpectedValueException', $exception);
 
57
        $this->assertSame(
 
58
            'Could not produce an instance of "DoctrineTest\\InstantiatorTestAsset\\AbstractClassAsset" '
 
59
            . 'via un-serialization, since an error was triggered in file "bar" at line "456"',
 
60
            $exception->getMessage()
 
61
        );
 
62
 
 
63
        $previous = $exception->getPrevious();
 
64
 
 
65
        $this->assertInstanceOf('Exception', $previous);
 
66
        $this->assertSame('foo', $previous->getMessage());
 
67
        $this->assertSame(123, $previous->getCode());
 
68
    }
 
69
}