mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,12 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Tests\Serializer\Encoder;
|
||||
|
||||
use Chill\DocGeneratorBundle\Serializer\Encoder\DocGenEncoder;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class DocGenEncoderTest extends TestCase
|
||||
{
|
||||
private DocGenEncoder $encoder;
|
||||
@@ -18,62 +28,32 @@ class DocGenEncoderTest extends TestCase
|
||||
$this->encoder = new DocGenEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateEncodeData
|
||||
*/
|
||||
public function testEncode($expected, $data, string $msg)
|
||||
{
|
||||
$generated = $this->encoder->encode($data, 'docgen');
|
||||
$this->assertEquals($expected, $generated, $msg);
|
||||
}
|
||||
|
||||
public function testEmbeddedLoopsThrowsException()
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
|
||||
$data = [
|
||||
'data' => [
|
||||
['item' => 'one'],
|
||||
[
|
||||
'embedded' => [
|
||||
[
|
||||
['subitem' => 'two'],
|
||||
['subitem' => 'three']
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->encoder->encode($data, 'docgen');
|
||||
}
|
||||
|
||||
public function generateEncodeData()
|
||||
{
|
||||
yield [ ['tests' => 'ok'], ['tests' => 'ok'], "A simple test with a simple array"];
|
||||
|
||||
yield [
|
||||
// expected:
|
||||
['item_subitem' => 'value'],
|
||||
// data:
|
||||
['item' => ['subitem' => 'value']],
|
||||
"A test with multidimensional array"
|
||||
];
|
||||
|
||||
yield [
|
||||
// expected:
|
||||
[ 'data' => [['item' => 'one'], ['item' => 'two']] ],
|
||||
// data:
|
||||
[ 'data' => [['item' => 'one'], ['item' => 'two']] ],
|
||||
"a list of items"
|
||||
];
|
||||
yield [['tests' => 'ok'], ['tests' => 'ok'], 'A simple test with a simple array'];
|
||||
|
||||
yield [
|
||||
// expected:
|
||||
[ 'data' => [['item_subitem' => 'alpha'], ['item' => 'two']] ],
|
||||
['item_subitem' => 'value'],
|
||||
// data:
|
||||
[ 'data' => [['item' => ['subitem' => 'alpha']], ['item' => 'two'] ] ],
|
||||
"a list of items with multidimensional array inside item"
|
||||
['item' => ['subitem' => 'value']],
|
||||
'A test with multidimensional array',
|
||||
];
|
||||
|
||||
yield [
|
||||
// expected:
|
||||
['data' => [['item' => 'one'], ['item' => 'two']]],
|
||||
// data:
|
||||
['data' => [['item' => 'one'], ['item' => 'two']]],
|
||||
'a list of items',
|
||||
];
|
||||
|
||||
yield [
|
||||
// expected:
|
||||
['data' => [['item_subitem' => 'alpha'], ['item' => 'two']]],
|
||||
// data:
|
||||
['data' => [['item' => ['subitem' => 'alpha']], ['item' => 'two']]],
|
||||
'a list of items with multidimensional array inside item',
|
||||
];
|
||||
|
||||
yield [
|
||||
@@ -88,9 +68,9 @@ class DocGenEncoderTest extends TestCase
|
||||
'father_firstname' => 'Marcel',
|
||||
'father_lastname' => 'Dupont',
|
||||
'father_dateOfBirth_long' => '10 novembre 1953',
|
||||
'father_dateOfBirth_short' => '10/11/1953'
|
||||
'father_dateOfBirth_short' => '10/11/1953',
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
// data:
|
||||
[
|
||||
@@ -98,16 +78,49 @@ class DocGenEncoderTest extends TestCase
|
||||
[
|
||||
'firstname' => 'Jonathan',
|
||||
'lastname' => 'Dupont',
|
||||
'dateOfBirth' => [ 'long' => '16 juin 1981', 'short' => '16/06/1981'],
|
||||
'dateOfBirth' => ['long' => '16 juin 1981', 'short' => '16/06/1981'],
|
||||
'father' => [
|
||||
'firstname' => 'Marcel',
|
||||
'lastname' => 'Dupont',
|
||||
'dateOfBirth' => ['long' => '10 novembre 1953', 'short' => '10/11/1953']
|
||||
]
|
||||
'dateOfBirth' => ['long' => '10 novembre 1953', 'short' => '10/11/1953'],
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
"a longer list, with near real data inside and embedded associative arrays"
|
||||
'a longer list, with near real data inside and embedded associative arrays',
|
||||
];
|
||||
}
|
||||
|
||||
public function testEmbeddedLoopsThrowsException()
|
||||
{
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
|
||||
$data = [
|
||||
'data' => [
|
||||
['item' => 'one'],
|
||||
[
|
||||
'embedded' => [
|
||||
[
|
||||
['subitem' => 'two'],
|
||||
['subitem' => 'three'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->encoder->encode($data, 'docgen');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider generateEncodeData
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $data
|
||||
*/
|
||||
public function testEncode($expected, $data, string $msg)
|
||||
{
|
||||
$generated = $this->encoder->encode($data, 'docgen');
|
||||
$this->assertEquals($expected, $generated, $msg);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user