Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

tests/Doctrine/Tests/DBAL/Types/JsonTest.php (2 issues)

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
7
8
class JsonTest extends \Doctrine\Tests\DbalTestCase
9
{
10
    /**
11
     * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform
12
     */
13
    protected $platform;
14
15
    /**
16
     * @var \Doctrine\DBAL\Types\JsonType
17
     */
18
    protected $type;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function setUp()
24
    {
25
        $this->platform = new MockPlatform();
26
        $this->type     = Type::getType('json');
27
    }
28
29
    public function testReturnsBindingType()
30
    {
31
        self::assertSame(\PDO::PARAM_STR, $this->type->getBindingType());
32
    }
33
34
    public function testReturnsName()
35
    {
36
        self::assertSame(Type::JSON, $this->type->getName());
37
    }
38
39
    public function testReturnsSQLDeclaration()
40
    {
41
        self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration(array(), $this->platform));
42
    }
43
44
    public function testJsonNullConvertsToPHPValue()
45
    {
46
        self::assertNull($this->type->convertToPHPValue(null, $this->platform));
47
    }
48
49
    public function testJsonEmptyStringConvertsToPHPValue()
50
    {
51
        self::assertNull($this->type->convertToPHPValue('', $this->platform));
52
    }
53
54 View Code Duplication
    public function testJsonStringConvertsToPHPValue()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $value         = array('foo' => 'bar', 'bar' => 'foo');
57
        $databaseValue = json_encode($value);
58
        $phpValue      = $this->type->convertToPHPValue($databaseValue, $this->platform);
59
60
        self::assertEquals($value, $phpValue);
61
    }
62
63
    /** @dataProvider providerFailure */
64
    public function testConversionFailure($data)
65
    {
66
        $this->expectException('Doctrine\DBAL\Types\ConversionException');
67
        $this->type->convertToPHPValue($data, $this->platform);
68
    }
69
70
    public function providerFailure()
71
    {
72
        return array(array('a'), array('{'));
73
    }
74
75 View Code Duplication
    public function testJsonResourceConvertsToPHPValue()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $value         = array('foo' => 'bar', 'bar' => 'foo');
78
        $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r');
79
        $phpValue      = $this->type->convertToPHPValue($databaseValue, $this->platform);
80
81
        self::assertSame($value, $phpValue);
82
    }
83
84
    public function testRequiresSQLCommentHint()
85
    {
86
        self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
87
    }
88
}
89