1 | <?php |
||
2 | |||
3 | namespace Doctrine\Tests\DBAL\Types; |
||
4 | |||
5 | use Doctrine\DBAL\Types\ConversionException; |
||
6 | |||
7 | class ConversionExceptionTest extends \PHPUnit\Framework\TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @dataProvider scalarsProvider |
||
11 | * |
||
12 | * @param mixed $scalarValue |
||
13 | */ |
||
14 | View Code Duplication | public function testConversionFailedInvalidTypeWithScalar($scalarValue) |
|
0 ignored issues
–
show
|
|||
15 | { |
||
16 | $exception = ConversionException::conversionFailedInvalidType($scalarValue, 'foo', ['bar', 'baz']); |
||
17 | |||
18 | self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); |
||
19 | self::assertRegExp( |
||
20 | '/^Could not convert PHP value \'.*\' of type \'(string|boolean|float|double|integer)\' to type \'foo\'. ' |
||
21 | . 'Expected one of the following types: bar, baz$/', |
||
22 | $exception->getMessage() |
||
23 | ); |
||
24 | } |
||
25 | /** |
||
26 | * @dataProvider nonScalarsProvider |
||
27 | * |
||
28 | * @param mixed $nonScalar |
||
29 | */ |
||
30 | View Code Duplication | public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) |
|
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...
|
|||
31 | { |
||
32 | $exception = ConversionException::conversionFailedInvalidType($nonScalar, 'foo', ['bar', 'baz']); |
||
33 | |||
34 | self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); |
||
35 | self::assertRegExp( |
||
36 | '/^Could not convert PHP value of type \'(.*)\' to type \'foo\'. ' |
||
37 | . 'Expected one of the following types: bar, baz$/', |
||
38 | $exception->getMessage() |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | View Code Duplication | public function testConversionFailedFormatPreservesPreviousException() |
|
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...
|
|||
43 | { |
||
44 | $previous = new \Exception(); |
||
45 | |||
46 | $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); |
||
47 | |||
48 | self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); |
||
49 | self::assertSame($previous, $exception->getPrevious()); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return mixed[][] |
||
54 | */ |
||
55 | public function nonScalarsProvider() |
||
56 | { |
||
57 | return [ |
||
58 | [[]], |
||
59 | [['foo']], |
||
60 | [null], |
||
61 | [$this], |
||
62 | [new \stdClass()], |
||
63 | [tmpfile()], |
||
64 | ]; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return mixed[][] |
||
69 | */ |
||
70 | View Code Duplication | public function scalarsProvider() |
|
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...
|
|||
71 | { |
||
72 | return [ |
||
73 | [''], |
||
74 | ['foo'], |
||
75 | [123], |
||
76 | [-123], |
||
77 | [12.34], |
||
78 | [true], |
||
79 | [false], |
||
80 | ]; |
||
81 | } |
||
82 | } |
||
83 |
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.