|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Smartbox\CoreBundle\Tests\Utils\Monolog\Formatter; |
|
4
|
|
|
|
|
5
|
|
|
use JMS\Serializer\SerializerInterface; |
|
6
|
|
|
use Smartbox\CoreBundle\Tests\Fixtures\Entity\TestEntity; |
|
7
|
|
|
use Smartbox\CoreBundle\Utils\Monolog\Formatter\JMSSerializerFormatter; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class JMSSerializerFormatterTest. |
|
12
|
|
|
* |
|
13
|
|
|
* @coversDefaultClass Smartbox\CoreBundle\Utils\Monolog\Formatter\JMSSerializerFormatter |
|
14
|
|
|
*/ |
|
15
|
|
|
class JMSSerializerFormatterTest extends WebTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var SerializerInterface */ |
|
18
|
|
|
private $serializer; |
|
19
|
|
|
|
|
20
|
|
|
public static function getKernelClass() |
|
21
|
|
|
{ |
|
22
|
|
|
return \Smartbox\CoreBundle\Tests\AppKernel::class; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp() |
|
26
|
|
|
{ |
|
27
|
|
|
static::bootKernel(); |
|
28
|
|
|
$container = static::$kernel->getContainer(); |
|
29
|
|
|
$this->serializer = $container->get('serializer'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
protected function tearDown() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::tearDown(); |
|
35
|
|
|
self::$class = null; |
|
36
|
|
|
$this->serializer = null; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function dataProviderForFormatter() |
|
40
|
|
|
{ |
|
41
|
|
|
$data = []; |
|
42
|
|
|
for ($i = 0; $i < 3; ++$i) { |
|
43
|
|
|
$data[] = [ |
|
44
|
|
|
sprintf( |
|
45
|
|
|
'[{"title":"title_%s","description":"description_%s","note":"note_%s","enabled":%s}]', |
|
46
|
|
|
$i, |
|
47
|
|
|
$i, |
|
48
|
|
|
$i, |
|
49
|
|
|
(($i % 2) ? 'true' : 'false') |
|
50
|
|
|
), |
|
51
|
|
|
(new TestEntity()) |
|
52
|
|
|
->setTitle('title_'.$i) |
|
53
|
|
|
->setDescription('description_'.$i) |
|
54
|
|
|
->setNote('note_'.$i) |
|
55
|
|
|
->setEnabled(($i % 2) ? true : false), |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $data; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider dataProviderForFormatter |
|
64
|
|
|
* |
|
65
|
|
|
* @param $expected |
|
66
|
|
|
* @param $entity |
|
67
|
|
|
* |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
public function testFormat($expected, TestEntity $entity) |
|
71
|
|
|
{ |
|
72
|
|
|
$formatter = new JMSSerializerFormatter(); |
|
73
|
|
|
$formatter->setSerializer($this->serializer); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals($expected, $formatter->format([$entity])); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|