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

tests/Doctrine/Tests/DBAL/Types/BlobTest.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 BlobTest extends \Doctrine\Tests\DbalTestCase
9
{
10
    /**
11
     * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform
12
     */
13
    protected $platform;
14
15
    /**
16
     * @var \Doctrine\DBAL\Types\BlobType
17
     */
18
    protected $type;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function setUp()
24
    {
25
        $this->platform = new MockPlatform();
26
        $this->type = Type::getType('blob');
27
    }
28
29
    public function testBlobNullConvertsToPHPValue()
30
    {
31
        self::assertNull($this->type->convertToPHPValue(null, $this->platform));
32
    }
33
34 View Code Duplication
    public function testBinaryStringConvertsToPHPValue()
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...
35
    {
36
        $databaseValue = $this->getBinaryString();
37
        $phpValue      = $this->type->convertToPHPValue($databaseValue, $this->platform);
38
39
        self::assertInternalType('resource', $phpValue);
40
        self::assertSame($databaseValue, stream_get_contents($phpValue));
41
    }
42
43 View Code Duplication
    public function testBinaryResourceConvertsToPHPValue()
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...
44
    {
45
        $databaseValue = fopen('data://text/plain;base64,' . base64_encode($this->getBinaryString()), 'r');
46
        $phpValue      = $this->type->convertToPHPValue($databaseValue, $this->platform);
47
48
        self::assertSame($databaseValue, $phpValue);
49
    }
50
51
    /**
52
     * Creates a binary string containing all possible byte values.
53
     *
54
     * @return string
55
     */
56
    private function getBinaryString()
57
    {
58
        $string = '';
59
60
        for ($i = 0; $i < 256; $i++) {
61
            $string .= chr($i);
62
        }
63
64
        return $string;
65
    }
66
}
67