b4b449f3586111356a3b58a78be1c21661c05210
[yaffs-website] / vendor / symfony / http-kernel / Tests / ControllerMetadata / ArgumentMetadataFactoryTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\ControllerMetadata;
13
14 use Fake\ImportedAndFake;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
17 use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
18 use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\BasicTypesController;
19 use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController;
20 use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController;
21
22 class ArgumentMetadataFactoryTest extends TestCase
23 {
24     /**
25      * @var ArgumentMetadataFactory
26      */
27     private $factory;
28
29     protected function setUp()
30     {
31         $this->factory = new ArgumentMetadataFactory();
32     }
33
34     public function testSignature1()
35     {
36         $arguments = $this->factory->createArgumentMetadata(array($this, 'signature1'));
37
38         $this->assertEquals(array(
39             new ArgumentMetadata('foo', self::class, false, false, null),
40             new ArgumentMetadata('bar', 'array', false, false, null),
41             new ArgumentMetadata('baz', 'callable', false, false, null),
42         ), $arguments);
43     }
44
45     public function testSignature2()
46     {
47         $arguments = $this->factory->createArgumentMetadata(array($this, 'signature2'));
48
49         $this->assertEquals(array(
50             new ArgumentMetadata('foo', self::class, false, true, null, true),
51             new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, true, null, true),
52             new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, true, null, true),
53         ), $arguments);
54     }
55
56     public function testSignature3()
57     {
58         $arguments = $this->factory->createArgumentMetadata(array($this, 'signature3'));
59
60         $this->assertEquals(array(
61             new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, false, null),
62             new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, false, null),
63         ), $arguments);
64     }
65
66     public function testSignature4()
67     {
68         $arguments = $this->factory->createArgumentMetadata(array($this, 'signature4'));
69
70         $this->assertEquals(array(
71             new ArgumentMetadata('foo', null, false, true, 'default'),
72             new ArgumentMetadata('bar', null, false, true, 500),
73             new ArgumentMetadata('baz', null, false, true, array()),
74         ), $arguments);
75     }
76
77     public function testSignature5()
78     {
79         $arguments = $this->factory->createArgumentMetadata(array($this, 'signature5'));
80
81         $this->assertEquals(array(
82             new ArgumentMetadata('foo', 'array', false, true, null, true),
83             new ArgumentMetadata('bar', null, false, false, null),
84         ), $arguments);
85     }
86
87     /**
88      * @requires PHP 5.6
89      */
90     public function testVariadicSignature()
91     {
92         $arguments = $this->factory->createArgumentMetadata(array(new VariadicController(), 'action'));
93
94         $this->assertEquals(array(
95             new ArgumentMetadata('foo', null, false, false, null),
96             new ArgumentMetadata('bar', null, true, false, null),
97         ), $arguments);
98     }
99
100     /**
101      * @requires PHP 7.0
102      */
103     public function testBasicTypesSignature()
104     {
105         $arguments = $this->factory->createArgumentMetadata(array(new BasicTypesController(), 'action'));
106
107         $this->assertEquals(array(
108             new ArgumentMetadata('foo', 'string', false, false, null),
109             new ArgumentMetadata('bar', 'int', false, false, null),
110             new ArgumentMetadata('baz', 'float', false, false, null),
111         ), $arguments);
112     }
113
114     /**
115      * @requires PHP 7.1
116      */
117     public function testNullableTypesSignature()
118     {
119         $arguments = $this->factory->createArgumentMetadata(array(new NullableController(), 'action'));
120
121         $this->assertEquals(array(
122             new ArgumentMetadata('foo', 'string', false, false, null, true),
123             new ArgumentMetadata('bar', \stdClass::class, false, false, null, true),
124             new ArgumentMetadata('baz', 'string', false, true, 'value', true),
125             new ArgumentMetadata('mandatory', null, false, false, null, true),
126         ), $arguments);
127     }
128
129     private function signature1(ArgumentMetadataFactoryTest $foo, array $bar, callable $baz)
130     {
131     }
132
133     private function signature2(ArgumentMetadataFactoryTest $foo = null, FakeClassThatDoesNotExist $bar = null, ImportedAndFake $baz = null)
134     {
135     }
136
137     private function signature3(FakeClassThatDoesNotExist $bar, ImportedAndFake $baz)
138     {
139     }
140
141     private function signature4($foo = 'default', $bar = 500, $baz = array())
142     {
143     }
144
145     private function signature5(array $foo = null, $bar)
146     {
147     }
148 }