PageRenderTime 77ms CodeModel.GetById 18ms app.highlight 53ms RepoModel.GetById 1ms app.codeStats 1ms

/vendor/phpunit/phpunit/tests/Util/TestTest.php

https://bitbucket.org/alan_cordova/api-sb-map
PHP | 823 lines | 703 code | 67 blank | 53 comment | 11 complexity | 8ca0cd7a872e3c3ebb68925178148b3b MD5 | raw file
  1<?php
  2/*
  3 * This file is part of PHPUnit.
  4 *
  5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6 *
  7 * For the full copyright and license information, please view the LICENSE
  8 * file that was distributed with this source code.
  9 */
 10
 11if (!defined('TEST_FILES_PATH')) {
 12    define(
 13        'TEST_FILES_PATH',
 14        dirname(__DIR__) . DIRECTORY_SEPARATOR .
 15        '_files' . DIRECTORY_SEPARATOR
 16    );
 17}
 18
 19require TEST_FILES_PATH . 'CoverageNamespacedFunctionTest.php';
 20require TEST_FILES_PATH . 'NamespaceCoveredFunction.php';
 21require TEST_FILES_PATH . 'MultipleDataProviderTest.php';
 22
 23class Util_TestTest extends PHPUnit_Framework_TestCase
 24{
 25    /**
 26     * @todo   Split up in separate tests
 27     */
 28    public function testGetExpectedException()
 29    {
 30        $this->assertArraySubset(
 31          ['class' => 'FooBarBaz', 'code' => null, 'message' => ''],
 32          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testOne')
 33        );
 34
 35        $this->assertArraySubset(
 36          ['class' => 'Foo_Bar_Baz', 'code' => null, 'message' => ''],
 37          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testTwo')
 38        );
 39
 40        $this->assertArraySubset(
 41          ['class' => 'Foo\Bar\Baz', 'code' => null, 'message' => ''],
 42          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testThree')
 43        );
 44
 45        $this->assertArraySubset(
 46          ['class' => 'ほげ', 'code' => null, 'message' => ''],
 47          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFour')
 48        );
 49
 50        $this->assertArraySubset(
 51          ['class' => 'Class', 'code' => 1234, 'message' => 'Message'],
 52          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testFive')
 53        );
 54
 55        $this->assertArraySubset(
 56          ['class' => 'Class', 'code' => 1234, 'message' => 'Message'],
 57          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSix')
 58        );
 59
 60        $this->assertArraySubset(
 61          ['class' => 'Class', 'code' => 'ExceptionCode', 'message' => 'Message'],
 62          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSeven')
 63        );
 64
 65        $this->assertArraySubset(
 66          ['class' => 'Class', 'code' => 0, 'message' => 'Message'],
 67          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testEight')
 68        );
 69
 70        $this->assertArraySubset(
 71          ['class' => 'Class', 'code' => ExceptionTest::ERROR_CODE, 'message' => ExceptionTest::ERROR_MESSAGE],
 72          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testNine')
 73        );
 74
 75        $this->assertArraySubset(
 76          ['class' => 'Class', 'code' => null, 'message' => ''],
 77          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testSingleLine')
 78        );
 79
 80        $this->assertArraySubset(
 81          ['class' => 'Class', 'code' => My\Space\ExceptionNamespaceTest::ERROR_CODE, 'message' => My\Space\ExceptionNamespaceTest::ERROR_MESSAGE],
 82          PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testConstants')
 83        );
 84
 85        // Ensure the Class::CONST expression is only evaluated when the constant really exists
 86        $this->assertArraySubset(
 87          ['class' => 'Class', 'code' => 'ExceptionTest::UNKNOWN_CODE_CONSTANT', 'message' => 'ExceptionTest::UNKNOWN_MESSAGE_CONSTANT'],
 88          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testUnknownConstants')
 89        );
 90
 91        $this->assertArraySubset(
 92          ['class' => 'Class', 'code' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_CODE_CONSTANT', 'message' => 'My\Space\ExceptionNamespaceTest::UNKNOWN_MESSAGE_CONSTANT'],
 93          PHPUnit_Util_Test::getExpectedException('My\Space\ExceptionNamespaceTest', 'testUnknownConstants')
 94        );
 95    }
 96
 97    public function testGetExpectedRegExp()
 98    {
 99        $this->assertArraySubset(
100          ['message_regex' => '#regex#'],
101          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessage')
102        );
103
104        $this->assertArraySubset(
105          ['message_regex' => '#regex#'],
106          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithRegexMessageFromClassConstant')
107        );
108
109        $this->assertArraySubset(
110          ['message_regex' => 'ExceptionTest::UNKNOWN_MESSAGE_REGEX_CONSTANT'],
111          PHPUnit_Util_Test::getExpectedException('ExceptionTest', 'testWithUnknowRegexMessageFromClassConstant')
112        );
113    }
114
115    /**
116     * @dataProvider requirementsProvider
117     */
118    public function testGetRequirements($test, $result)
119    {
120        $this->assertEquals(
121            $result,
122            PHPUnit_Util_Test::getRequirements('RequirementsTest', $test)
123        );
124    }
125
126    public function requirementsProvider()
127    {
128        return [
129            ['testOne',    []],
130            ['testTwo',    ['PHPUnit'    => ['version' => '1.0', 'operator' => '']]],
131            ['testThree',  ['PHP'        => ['version' => '2.0', 'operator' => '']]],
132            ['testFour',   [
133                'PHPUnit'    => ['version' => '2.0', 'operator' => ''],
134                'PHP'        => ['version' => '1.0', 'operator' => '']]
135            ],
136            ['testFive',   ['PHP'        => ['version' => '5.4.0RC6', 'operator' => '']]],
137            ['testSix',    ['PHP'        => ['version' => '5.4.0-alpha1', 'operator' => '']]],
138            ['testSeven',  ['PHP'        => ['version' => '5.4.0beta2', 'operator' => '']]],
139            ['testEight',  ['PHP'        => ['version' => '5.4-dev', 'operator' => '']]],
140            ['testNine',   ['functions'  => ['testFunc']]],
141            ['testTen',    ['extensions' => ['testExt']]],
142            ['testEleven', ['OS'         => '/Linux/i']],
143            [
144              'testSpace',
145              [
146                'extensions' => ['spl'],
147                'OS'         => '/.*/i'
148              ]
149            ],
150            [
151              'testAllPossibleRequirements',
152              [
153                'PHP'       => ['version' => '99-dev', 'operator' => ''],
154                'PHPUnit'   => ['version' => '9-dev', 'operator' => ''],
155                'OS'        => '/DOESNOTEXIST/i',
156                'functions' => [
157                  'testFuncOne',
158                  'testFuncTwo',
159                ],
160                'extensions' => [
161                  'testExtOne',
162                  'testExtTwo',
163                  'testExtThree',
164                ],
165                'extension_versions' => [
166                    'testExtThree' => ['version' => '2.0', 'operator' => '']
167                ]
168              ]
169            ],
170            ['testSpecificExtensionVersion',
171                [
172                    'extension_versions' => ['testExt' => ['version' => '1.8.0', 'operator' => '']],
173                    'extensions'         => ['testExt']
174                ]
175            ],
176            ['testPHPVersionOperatorLessThan',
177                [
178                    'PHP' => ['version' => '5.4', 'operator' => '<']
179                ]
180            ],
181            ['testPHPVersionOperatorLessThanEquals',
182                [
183                    'PHP' => ['version' => '5.4', 'operator' => '<=']
184                ]
185            ],
186            ['testPHPVersionOperatorGreaterThan',
187                [
188                    'PHP' => ['version' => '99', 'operator' => '>']
189                ]
190            ],
191            ['testPHPVersionOperatorGreaterThanEquals',
192                [
193                    'PHP' => ['version' => '99', 'operator' => '>=']
194                ]
195            ],
196            ['testPHPVersionOperatorEquals',
197                [
198                    'PHP' => ['version' => '5.4', 'operator' => '=']
199                ]
200            ],
201            ['testPHPVersionOperatorDoubleEquals',
202                [
203                    'PHP' => ['version' => '5.4', 'operator' => '==']
204                ]
205            ],
206            ['testPHPVersionOperatorBangEquals',
207                [
208                    'PHP' => ['version' => '99', 'operator' => '!=']
209                ]
210            ],
211            ['testPHPVersionOperatorNotEquals',
212                [
213                    'PHP' => ['version' => '99', 'operator' => '<>']
214                ]
215            ],
216            ['testPHPVersionOperatorNoSpace',
217                [
218                    'PHP' => ['version' => '99', 'operator' => '>=']
219                ]
220            ],
221            ['testPHPUnitVersionOperatorLessThan',
222                [
223                    'PHPUnit' => ['version' => '1.0', 'operator' => '<']
224                ]
225            ],
226            ['testPHPUnitVersionOperatorLessThanEquals',
227                [
228                    'PHPUnit' => ['version' => '1.0', 'operator' => '<=']
229                ]
230            ],
231            ['testPHPUnitVersionOperatorGreaterThan',
232                [
233                    'PHPUnit' => ['version' => '99', 'operator' => '>']
234                ]
235            ],
236            ['testPHPUnitVersionOperatorGreaterThanEquals',
237                [
238                    'PHPUnit' => ['version' => '99', 'operator' => '>=']
239                ]
240            ],
241            ['testPHPUnitVersionOperatorEquals',
242                [
243                    'PHPUnit' => ['version' => '1.0', 'operator' => '=']
244                ]
245            ],
246            ['testPHPUnitVersionOperatorDoubleEquals',
247                [
248                    'PHPUnit' => ['version' => '1.0', 'operator' => '==']
249                ]
250            ],
251            ['testPHPUnitVersionOperatorBangEquals',
252                [
253                    'PHPUnit' => ['version' => '99', 'operator' => '!=']
254                ]
255            ],
256            ['testPHPUnitVersionOperatorNotEquals',
257                [
258                    'PHPUnit' => ['version' => '99', 'operator' => '<>']
259                ]
260            ],
261            ['testPHPUnitVersionOperatorNoSpace',
262                [
263                    'PHPUnit' => ['version' => '99', 'operator' => '>=']
264                ]
265            ],
266            ['testExtensionVersionOperatorLessThanEquals',
267                [
268                    'extensions'         => ['testExtOne'],
269                    'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '<=']]
270                ]
271            ],
272            ['testExtensionVersionOperatorGreaterThan',
273                [
274                    'extensions'         => ['testExtOne'],
275                    'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>']]
276                ]
277            ],
278            ['testExtensionVersionOperatorGreaterThanEquals',
279                [
280                    'extensions'         => ['testExtOne'],
281                    'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']]
282                ]
283            ],
284            ['testExtensionVersionOperatorEquals',
285                [
286                    'extensions'         => ['testExtOne'],
287                    'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '=']]
288                ]
289            ],
290            ['testExtensionVersionOperatorDoubleEquals',
291                [
292                    'extensions'         => ['testExtOne'],
293                    'extension_versions' => ['testExtOne' => ['version' => '1.0', 'operator' => '==']]
294                ]
295            ],
296            ['testExtensionVersionOperatorBangEquals',
297                [
298                    'extensions'         => ['testExtOne'],
299                    'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '!=']]
300                ]
301            ],
302            ['testExtensionVersionOperatorNotEquals',
303                [
304                    'extensions'         => ['testExtOne'],
305                    'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '<>']]
306                ]
307            ],
308            ['testExtensionVersionOperatorNoSpace',
309                [
310                    'extensions'         => ['testExtOne'],
311                    'extension_versions' => ['testExtOne' => ['version' => '99', 'operator' => '>=']]
312                ]
313            ],
314        ];
315    }
316
317    public function testGetRequirementsMergesClassAndMethodDocBlocks()
318    {
319        $expectedAnnotations = [
320            'PHP'       => ['version' => '5.4', 'operator' => ''],
321            'PHPUnit'   => ['version' => '3.7', 'operator' => ''],
322            'OS'        => '/WINNT/i',
323            'functions' => [
324              'testFuncClass',
325              'testFuncMethod',
326            ],
327            'extensions' => [
328              'testExtClass',
329              'testExtMethod',
330            ]
331        ];
332
333        $this->assertEquals(
334            $expectedAnnotations,
335            PHPUnit_Util_Test::getRequirements('RequirementsClassDocBlockTest', 'testMethod')
336        );
337    }
338
339    /**
340     * @dataProvider missingRequirementsProvider
341     */
342    public function testGetMissingRequirements($test, $result)
343    {
344        $this->assertEquals(
345            $result,
346            PHPUnit_Util_Test::getMissingRequirements('RequirementsTest', $test)
347        );
348    }
349
350    public function missingRequirementsProvider()
351    {
352        return [
353            ['testOne',            []],
354            ['testNine',           ['Function testFunc is required.']],
355            ['testTen',            ['Extension testExt is required.']],
356            ['testAlwaysSkip',     ['PHPUnit >= 1111111 is required.']],
357            ['testAlwaysSkip2',    ['PHP >= 9999999 is required.']],
358            ['testAlwaysSkip3',    ['Operating system matching /DOESNOTEXIST/i is required.']],
359            ['testAllPossibleRequirements', [
360              'PHP >= 99-dev is required.',
361              'PHPUnit >= 9-dev is required.',
362              'Operating system matching /DOESNOTEXIST/i is required.',
363              'Function testFuncOne is required.',
364              'Function testFuncTwo is required.',
365              'Extension testExtOne is required.',
366              'Extension testExtTwo is required.',
367              'Extension testExtThree >= 2.0 is required.',
368            ]],
369            ['testPHPVersionOperatorLessThan', ['PHP < 5.4 is required.']],
370            ['testPHPVersionOperatorLessThanEquals', ['PHP <= 5.4 is required.']],
371            ['testPHPVersionOperatorGreaterThan', ['PHP > 99 is required.']],
372            ['testPHPVersionOperatorGreaterThanEquals', ['PHP >= 99 is required.']],
373            ['testPHPVersionOperatorNoSpace', ['PHP >= 99 is required.']],
374            ['testPHPVersionOperatorEquals', ['PHP = 5.4 is required.']],
375            ['testPHPVersionOperatorDoubleEquals', ['PHP == 5.4 is required.']],
376            ['testPHPUnitVersionOperatorLessThan', ['PHPUnit < 1.0 is required.']],
377            ['testPHPUnitVersionOperatorLessThanEquals', ['PHPUnit <= 1.0 is required.']],
378            ['testPHPUnitVersionOperatorGreaterThan', ['PHPUnit > 99 is required.']],
379            ['testPHPUnitVersionOperatorGreaterThanEquals', ['PHPUnit >= 99 is required.']],
380            ['testPHPUnitVersionOperatorEquals', ['PHPUnit = 1.0 is required.']],
381            ['testPHPUnitVersionOperatorDoubleEquals', ['PHPUnit == 1.0 is required.']],
382            ['testPHPUnitVersionOperatorNoSpace', ['PHPUnit >= 99 is required.']],
383            ['testExtensionVersionOperatorLessThan', ['Extension testExtOne < 1.0 is required.']],
384            ['testExtensionVersionOperatorLessThanEquals', ['Extension testExtOne <= 1.0 is required.']],
385            ['testExtensionVersionOperatorGreaterThan', ['Extension testExtOne > 99 is required.']],
386            ['testExtensionVersionOperatorGreaterThanEquals', ['Extension testExtOne >= 99 is required.']],
387            ['testExtensionVersionOperatorEquals', ['Extension testExtOne = 1.0 is required.']],
388            ['testExtensionVersionOperatorDoubleEquals', ['Extension testExtOne == 1.0 is required.']],
389            ['testExtensionVersionOperatorNoSpace', ['Extension testExtOne >= 99 is required.']],
390        ];
391    }
392
393    /**
394     * @todo   This test does not really test functionality of PHPUnit_Util_Test
395     */
396    public function testGetProvidedDataRegEx()
397    {
398        $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider method', $matches);
399        $this->assertEquals(1, $result);
400        $this->assertEquals('method', $matches[1]);
401
402        $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider class::method', $matches);
403        $this->assertEquals(1, $result);
404        $this->assertEquals('class::method', $matches[1]);
405
406        $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\class::method', $matches);
407        $this->assertEquals(1, $result);
408        $this->assertEquals('namespace\class::method', $matches[1]);
409
410        $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider namespace\namespace\class::method', $matches);
411        $this->assertEquals(1, $result);
412        $this->assertEquals('namespace\namespace\class::method', $matches[1]);
413
414        $result = preg_match(PHPUnit_Util_Test::REGEX_DATA_PROVIDER, '@dataProvider メソッド', $matches);
415        $this->assertEquals(1, $result);
416        $this->assertEquals('メソッド', $matches[1]);
417    }
418
419    /**
420     * Check if all data providers are being merged.
421     */
422    public function testMultipleDataProviders()
423    {
424        $dataSets = PHPUnit_Util_Test::getProvidedData('MultipleDataProviderTest', 'testOne');
425
426        $this->assertCount(9, $dataSets);
427
428        $aCount = 0;
429        $bCount = 0;
430        $cCount = 0;
431
432        for ($i = 0; $i < 9; $i++) {
433            $aCount += $dataSets[$i][0] != null ? 1 : 0;
434            $bCount += $dataSets[$i][1] != null ? 1 : 0;
435            $cCount += $dataSets[$i][2] != null ? 1 : 0;
436        }
437
438        $this->assertEquals(3, $aCount);
439        $this->assertEquals(3, $bCount);
440        $this->assertEquals(3, $cCount);
441    }
442
443    /**
444     * Check with a multiple yield / iterator data providers.
445     */
446    public function testMultipleYieldIteratorDataProviders()
447    {
448        $dataSets = PHPUnit_Util_Test::getProvidedData('MultipleDataProviderTest', 'testTwo');
449
450        $this->assertEquals(9, count($dataSets));
451
452        $aCount = 0;
453        $bCount = 0;
454        $cCount = 0;
455
456        for ($i = 0; $i < 9; $i++) {
457            $aCount += $dataSets[$i][0] != null ? 1 : 0;
458            $bCount += $dataSets[$i][1] != null ? 1 : 0;
459            $cCount += $dataSets[$i][2] != null ? 1 : 0;
460        }
461
462        $this->assertEquals(3, $aCount);
463        $this->assertEquals(3, $bCount);
464        $this->assertEquals(3, $cCount);
465    }
466
467    public function testTestWithEmptyAnnotation()
468    {
469        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation("/**\n * @anotherAnnotation\n */");
470        $this->assertNull($result);
471    }
472
473    public function testTestWithSimpleCase()
474    {
475        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
476                                                                     * @testWith [1]
477                                                                     */');
478        $this->assertEquals([[1]], $result);
479    }
480
481    public function testTestWithMultiLineMultiParameterCase()
482    {
483        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
484                                                                     * @testWith [1, 2]
485                                                                     * [3, 4]
486                                                                     */');
487        $this->assertEquals([[1, 2], [3, 4]], $result);
488    }
489
490    public function testTestWithVariousTypes()
491    {
492        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
493            * @testWith ["ab"]
494            *           [true]
495            *           [null]
496         */');
497        $this->assertEquals([['ab'], [true], [null]], $result);
498    }
499
500    public function testTestWithAnnotationAfter()
501    {
502        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
503                                                                     * @testWith [1]
504                                                                     *           [2]
505                                                                     * @annotation
506                                                                     */');
507        $this->assertEquals([[1], [2]], $result);
508    }
509
510    public function testTestWithSimpleTextAfter()
511    {
512        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
513                                                                     * @testWith [1]
514                                                                     *           [2]
515                                                                     * blah blah
516                                                                     */');
517        $this->assertEquals([[1], [2]], $result);
518    }
519
520    public function testTestWithCharacterEscape()
521    {
522        $result = PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
523                                                                     * @testWith ["\"", "\""]
524                                                                     */');
525        $this->assertEquals([['"', '"']], $result);
526    }
527
528    public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed()
529    {
530        $this->expectException(PHPUnit_Framework_Exception::class);
531        $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/');
532
533        PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
534                                                           * @testWith [s]
535                                                           */');
536    }
537
538    public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParsed()
539    {
540        $this->expectException(PHPUnit_Framework_Exception::class);
541        $this->expectExceptionMessageRegExp('/^The dataset for the @testWith annotation cannot be parsed:/');
542
543        PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
544                                                           * @testWith ["valid"]
545                                                           *           [invalid]
546                                                           */');
547    }
548
549    /**
550     * @todo   Not sure what this test tests (name is misleading at least)
551     */
552    public function testParseAnnotation()
553    {
554        $this->assertEquals(
555            ['Foo', 'ほげ'],
556            PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotation')
557        );
558    }
559
560    /**
561     * @depends Foo
562     * @depends ほげ
563     *
564     * @todo    Remove fixture from test class
565     */
566    public function methodForTestParseAnnotation()
567    {
568    }
569
570    public function testParseAnnotationThatIsOnlyOneLine()
571    {
572        $this->assertEquals(
573            ['Bar'],
574            PHPUnit_Util_Test::getDependencies(get_class($this), 'methodForTestParseAnnotationThatIsOnlyOneLine')
575        );
576    }
577
578    /** @depends Bar */
579    public function methodForTestParseAnnotationThatIsOnlyOneLine()
580    {
581        // TODO Remove fixture from test class
582    }
583
584    /**
585     * @dataProvider getLinesToBeCoveredProvider
586     */
587    public function testGetLinesToBeCovered($test, $lines)
588    {
589        if (strpos($test, 'Namespace') === 0) {
590            $expected = [
591              TEST_FILES_PATH . 'NamespaceCoveredClass.php' => $lines
592            ];
593        } elseif ($test === 'CoverageNoneTest') {
594            $expected = [];
595        } elseif ($test === 'CoverageNothingTest') {
596            $expected = false;
597        } elseif ($test === 'CoverageFunctionTest') {
598            $expected = [
599              TEST_FILES_PATH . 'CoveredFunction.php' => $lines
600            ];
601        } else {
602            $expected = [TEST_FILES_PATH . 'CoveredClass.php' => $lines];
603        }
604
605        $this->assertEquals(
606            $expected,
607            PHPUnit_Util_Test::getLinesToBeCovered(
608                $test, 'testSomething'
609            )
610        );
611    }
612
613    /**
614     * @expectedException PHPUnit_Framework_CodeCoverageException
615     */
616    public function testGetLinesToBeCovered2()
617    {
618        PHPUnit_Util_Test::getLinesToBeCovered(
619            'NotExistingCoveredElementTest', 'testOne'
620        );
621    }
622
623    /**
624     * @expectedException PHPUnit_Framework_CodeCoverageException
625     */
626    public function testGetLinesToBeCovered3()
627    {
628        PHPUnit_Util_Test::getLinesToBeCovered(
629            'NotExistingCoveredElementTest', 'testTwo'
630        );
631    }
632
633    /**
634     * @expectedException PHPUnit_Framework_CodeCoverageException
635     */
636    public function testGetLinesToBeCovered4()
637    {
638        PHPUnit_Util_Test::getLinesToBeCovered(
639            'NotExistingCoveredElementTest', 'testThree'
640        );
641    }
642
643    public function testGetLinesToBeCoveredSkipsNonExistentMethods()
644    {
645        $this->assertSame(
646            [],
647            PHPUnit_Util_Test::getLinesToBeCovered(
648                'NotExistingCoveredElementTest',
649                'methodDoesNotExist'
650            )
651        );
652    }
653
654    /**
655     * @expectedException PHPUnit_Framework_CodeCoverageException
656     */
657    public function testTwoCoversDefaultClassAnnoationsAreNotAllowed()
658    {
659        PHPUnit_Util_Test::getLinesToBeCovered(
660            'CoverageTwoDefaultClassAnnotations',
661            'testSomething'
662        );
663    }
664
665    public function testFunctionParenthesesAreAllowed()
666    {
667        $this->assertSame(
668            [TEST_FILES_PATH . 'CoveredFunction.php' => range(2, 4)],
669            PHPUnit_Util_Test::getLinesToBeCovered(
670                'CoverageFunctionParenthesesTest',
671                'testSomething'
672            )
673        );
674    }
675
676    public function testFunctionParenthesesAreAllowedWithWhitespace()
677    {
678        $this->assertSame(
679            [TEST_FILES_PATH . 'CoveredFunction.php' => range(2, 4)],
680            PHPUnit_Util_Test::getLinesToBeCovered(
681                'CoverageFunctionParenthesesWhitespaceTest',
682                'testSomething'
683            )
684        );
685    }
686
687    public function testMethodParenthesesAreAllowed()
688    {
689        $this->assertSame(
690            [TEST_FILES_PATH . 'CoveredClass.php' => range(31, 35)],
691            PHPUnit_Util_Test::getLinesToBeCovered(
692                'CoverageMethodParenthesesTest',
693                'testSomething'
694            )
695        );
696    }
697
698    public function testMethodParenthesesAreAllowedWithWhitespace()
699    {
700        $this->assertSame(
701            [TEST_FILES_PATH . 'CoveredClass.php' => range(31, 35)],
702            PHPUnit_Util_Test::getLinesToBeCovered(
703                'CoverageMethodParenthesesWhitespaceTest',
704                'testSomething'
705            )
706        );
707    }
708
709    public function testNamespacedFunctionCanBeCoveredOrUsed()
710    {
711        $this->assertEquals(
712            [
713                TEST_FILES_PATH . 'NamespaceCoveredFunction.php' => range(4, 7)
714            ],
715            PHPUnit_Util_Test::getLinesToBeCovered(
716                'CoverageNamespacedFunctionTest',
717                'testFunc'
718            )
719        );
720    }
721
722    public function getLinesToBeCoveredProvider()
723    {
724        return [
725          [
726            'CoverageNoneTest',
727            []
728          ],
729          [
730            'CoverageClassExtendedTest',
731            array_merge(range(19, 36), range(2, 17))
732          ],
733          [
734            'CoverageClassTest',
735            range(19, 36)
736          ],
737          [
738            'CoverageMethodTest',
739            range(31, 35)
740          ],
741          [
742            'CoverageMethodOneLineAnnotationTest',
743            range(31, 35)
744          ],
745          [
746            'CoverageNotPrivateTest',
747            array_merge(range(25, 29), range(31, 35))
748          ],
749          [
750            'CoverageNotProtectedTest',
751            array_merge(range(21, 23), range(31, 35))
752          ],
753          [
754            'CoverageNotPublicTest',
755            array_merge(range(21, 23), range(25, 29))
756          ],
757          [
758            'CoveragePrivateTest',
759            range(21, 23)
760          ],
761          [
762            'CoverageProtectedTest',
763            range(25, 29)
764          ],
765          [
766            'CoveragePublicTest',
767            range(31, 35)
768          ],
769          [
770            'CoverageFunctionTest',
771            range(2, 4)
772          ],
773          [
774            'NamespaceCoverageClassExtendedTest',
775            array_merge(range(21, 38), range(4, 19))
776          ],
777          [
778            'NamespaceCoverageClassTest',
779            range(21, 38)
780          ],
781          [
782            'NamespaceCoverageMethodTest',
783            range(33, 37)
784          ],
785          [
786            'NamespaceCoverageNotPrivateTest',
787            array_merge(range(27, 31), range(33, 37))
788          ],
789          [
790            'NamespaceCoverageNotProtectedTest',
791            array_merge(range(23, 25), range(33, 37))
792          ],
793          [
794            'NamespaceCoverageNotPublicTest',
795            array_merge(range(23, 25), range(27, 31))
796          ],
797          [
798            'NamespaceCoveragePrivateTest',
799            range(23, 25)
800          ],
801          [
802            'NamespaceCoverageProtectedTest',
803            range(27, 31)
804          ],
805          [
806            'NamespaceCoveragePublicTest',
807            range(33, 37)
808          ],
809          [
810            'NamespaceCoverageCoversClassTest',
811            array_merge(range(23, 25), range(27, 31), range(33, 37), range(6, 8), range(10, 13), range(15, 18))
812          ],
813          [
814            'NamespaceCoverageCoversClassPublicTest',
815            range(33, 37)
816          ],
817          [
818            'CoverageNothingTest',
819            false
820          ]
821        ];
822    }
823}