| Conditions | 1 |
| Paths | 1 |
| Total Lines | 37 |
| Code Lines | 25 |
| Lines | 7 |
| Ratio | 18.92 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 39 | public function setIterableWithDeferTaskConfiguration(CliGuy $I) |
||
| 40 | { |
||
| 41 | $I->wantTo('set iterable with deferTaskConfiguration()'); |
||
| 42 | |||
| 43 | $expected = [ |
||
| 44 | 'a = b', |
||
| 45 | 'c = d', |
||
| 46 | 'e = f', |
||
| 47 | ]; |
||
| 48 | $actual = []; |
||
| 49 | $I |
||
| 50 | ->collectionBuilder() |
||
| 51 | ->addCode(function (Data $data) { |
||
| 52 | $data['items'] = [ |
||
| 53 | 'a' => 'b', |
||
| 54 | 'c' => 'd', |
||
| 55 | 'e' => 'f', |
||
| 56 | ]; |
||
| 57 | |||
| 58 | return 0; |
||
| 59 | }) |
||
| 60 | ->addTask( |
||
| 61 | $I |
||
| 62 | ->taskForEach() |
||
| 63 | ->deferTaskConfiguration('setIterable', 'items') |
||
| 64 | View Code Duplication | ->withBuilder(function (CollectionBuilder $builder, $key, $value) use (&$actual) { |
|
| 65 | $builder->addCode(function () use ($key, $value, &$actual) { |
||
| 66 | $actual[] = "$key = $value"; |
||
| 67 | |||
| 68 | return 0; |
||
| 69 | }); |
||
| 70 | }) |
||
| 71 | ) |
||
| 72 | ->run(); |
||
| 73 | |||
| 74 | $I->assertEquals($expected, $actual); |
||
| 75 | } |
||
| 76 | } |
||
| 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: