Completed
Pull Request — master (#3254)
by Farhad
14:30
created

ObjectTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
7
use function serialize;
8
9
class ObjectTest extends \Doctrine\Tests\DbalTestCase
10
{
11
    /**
12
     * @var MockPlatform
13
     */
14
    protected $_platform;
15
16
    /**
17
     * @var Type
18
     */
19
    protected $_type;
20
21
    protected function setUp()
22
    {
23
        $this->_platform = new MockPlatform();
24
        $this->_type = Type::getType('object');
25
    }
26
27
    public function testObjectConvertsToDatabaseValue()
28
    {
29
        self::assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform));
30
    }
31
32
    public function testObjectConvertsToPHPValue()
33
    {
34
        self::assertInternalType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform));
35
    }
36
37
    public function testConversionFailure()
38
    {
39
        $this->expectException('Doctrine\DBAL\Types\ConversionException');
40
        $this->expectExceptionMessage("Could not convert database value to 'object' as an error was triggered by the unserialization: 'unserialize(): Error at offset 0 of 7 bytes'");
41
        $this->_type->convertToPHPValue('abcdefg', $this->_platform);
42
    }
43
44
    public function testNullConversion()
45
    {
46
        self::assertNull($this->_type->convertToPHPValue(null, $this->_platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->_type->convertToP...null, $this->_platform) targeting Doctrine\DBAL\Types\Type::convertToPHPValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
    }
48
49
    /**
50
     * @group DBAL-73
51
     */
52
    public function testFalseConversion()
53
    {
54
        self::assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform));
55
    }
56
}
57