Conditions | 2 |
Paths | 2 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | function testGenerate() |
||
28 | { |
||
29 | $this->markTestSkipped( |
||
30 | 'This test is not passing.' |
||
31 | ); |
||
32 | $pdf = $this->getPdfLabel(); |
||
33 | |||
34 | for ($i = 0; $i < 10; $i++) { |
||
35 | $contacts[$i] = array( |
||
|
|||
36 | 'number' => $i, |
||
37 | 'name' => 'Test'.$i, |
||
38 | 'address' => array('address' => 'Vej '.$i, |
||
39 | 'postcode' => '100'.$i, |
||
40 | 'city' => 'By '.$i, |
||
41 | 'country' => 'Land '.$i |
||
42 | ) |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | $pdf->generate($contacts, 'random search', array('keyword1', 'keyword2')); |
||
47 | |||
48 | // file_put_contents(TEST_PATH_TEMP.'pdf_label.pdf', $pdf->output()); |
||
49 | |||
50 | $this->assertEquals(strlen(file_get_contents(dirname(__FILE__) .'/expected/pdf_label.pdf', 1)), strlen($pdf->output())); |
||
51 | } |
||
52 | } |
||
53 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.