| Conditions | 1 |
| Paths | 1 |
| Total Lines | 30 |
| Code Lines | 19 |
| Lines | 7 |
| Ratio | 23.33 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | public function setIterableInConstructor(CliGuy $I) |
||
| 9 | { |
||
| 10 | $expected = [ |
||
| 11 | 'a = b', |
||
| 12 | 'c = d', |
||
| 13 | 'e = f', |
||
| 14 | ]; |
||
| 15 | |||
| 16 | $actual = []; |
||
| 17 | |||
| 18 | $items = [ |
||
| 19 | 'a' => 'b', |
||
| 20 | 'c' => 'd', |
||
| 21 | 'e' => 'f', |
||
| 22 | ]; |
||
| 23 | |||
| 24 | $I->wantTo('set iterable in the __constructor'); |
||
| 25 | $I |
||
| 26 | ->taskForEach($items) |
||
| 27 | View Code Duplication | ->withBuilder(function (CollectionBuilder $builder, $key, $value) use (&$actual) { |
|
| 28 | $builder->addCode(function () use ($key, $value, &$actual) { |
||
| 29 | $actual[] = "$key = $value"; |
||
| 30 | |||
| 31 | return 0; |
||
| 32 | }); |
||
| 33 | }) |
||
| 34 | ->run(); |
||
| 35 | |||
| 36 | $I->assertEquals($expected, $actual); |
||
| 37 | } |
||
| 38 | |||
| 77 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: