Completed
Push — develop ( 40c4f3...ed7ad1 )
by Sergei
62:39
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\ConversionException;
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
8
use Doctrine\Tests\DbalTestCase;
9
use stdClass;
10
use function serialize;
11
12
class ObjectTest extends DbalTestCase
13
{
14
    /** @var MockPlatform */
15
    private $platform;
16
17
    /** @var Type */
18
    private $type;
19
20
    protected function setUp()
21
    {
22
        $this->platform = new MockPlatform();
23
        $this->type     = Type::getType('object');
24
    }
25
26
    public function testObjectConvertsToDatabaseValue()
27
    {
28
        self::assertInternalType('string', $this->type->convertToDatabaseValue(new stdClass(), $this->platform));
29
    }
30
31
    public function testObjectConvertsToPHPValue()
32
    {
33
        self::assertInternalType('object', $this->type->convertToPHPValue(serialize(new stdClass()), $this->platform));
34
    }
35
36
    public function testConversionFailure()
37
    {
38
        $this->expectException(ConversionException::class);
39
        $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'");
40
        $this->type->convertToPHPValue('abcdefg', $this->platform);
41
    }
42
43
    public function testNullConversion()
44
    {
45
        self::assertNull($this->type->convertToPHPValue(null, $this->platform));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->type->convertToPH...(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...
46
    }
47
48
    /**
49
     * @group DBAL-73
50
     */
51
    public function testFalseConversion()
52
    {
53
        self::assertFalse($this->type->convertToPHPValue(serialize(false), $this->platform));
54
    }
55
}
56