-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathArrayFirstTransformerTest.php
More file actions
80 lines (60 loc) · 2.48 KB
/
ArrayFirstTransformerTest.php
File metadata and controls
80 lines (60 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (c) Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CleverAge\ProcessBundle\Tests\Transformer\Array;
use CleverAge\ProcessBundle\Transformer\Array\ArrayFirstTransformer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\OptionsResolver\OptionsResolver;
#[\PHPUnit\Framework\Attributes\CoversClass(ArrayFirstTransformer::class)]
#[\PHPUnit\Framework\Attributes\CoversMethod(ArrayFirstTransformer::class, 'transform')]
#[\PHPUnit\Framework\Attributes\CoversMethod(ArrayFirstTransformer::class, 'getCode')]
#[\PHPUnit\Framework\Attributes\CoversMethod(ArrayFirstTransformer::class, 'configureOptions')]
class ArrayFirstTransformerTest extends TestCase
{
public function testTransformReturnsFirstElementIfIterableAndAllowed(): void
{
$transformer = new ArrayFirstTransformer();
$value = [1, 2, 3];
$options = ['allow_not_iterable' => false];
$result = $transformer->transform($value, $options);
$this->assertEquals(1, $result);
}
public function testTransformReturnsValueIfNotIterableAndAllowed(): void
{
$this->expectException(\TypeError::class);
$transformer = new ArrayFirstTransformer();
$value = 'not_iterable_value';
$options = ['allow_not_iterable' => true];
$result = $transformer->transform($value, $options);
$this->assertEquals('not_iterable_value', $result);
}
public function testTransformThrowsExceptionIfNotIterableAndNotAllowed(): void
{
$transformer = new ArrayFirstTransformer();
$value = 'not_iterable_value';
$options = ['allow_not_iterable' => false];
$result = $transformer->transform($value, $options);
$this->assertEquals($value, $result);
}
public function testGetCodeReturnsCorrectCode(): void
{
$transformer = new ArrayFirstTransformer();
$code = $transformer->getCode();
$this->assertEquals('array_first', $code);
}
public function testConfigureOptionsSetsDefaultOptions(): void
{
$resolver = new OptionsResolver();
$transformer = new ArrayFirstTransformer();
$transformer->configureOptions($resolver);
$resolvedOptions = $resolver->resolve();
$this->assertEquals(['allow_not_iterable' => false], $resolvedOptions);
}
}