PageRenderTime 22ms CodeModel.GetById 8ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/phpunit/php-code-coverage/tests/tests/FilterTest.php

https://bitbucket.org/alan_cordova/api-sb-map
PHP | 194 lines | 122 code | 23 blank | 49 comment | 0 complexity | b43eb79f969e144c5619743f73106ec9 MD5 | raw file
  1<?php
  2/*
  3 * This file is part of the php-code-coverage package.
  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
 11namespace SebastianBergmann\CodeCoverage;
 12
 13class FilterTest extends \PHPUnit_Framework_TestCase
 14{
 15    /**
 16     * @var Filter
 17     */
 18    private $filter;
 19
 20    /**
 21     * @var array
 22     */
 23    private $files = [];
 24
 25    protected function setUp()
 26    {
 27        $this->filter = unserialize('O:37:"SebastianBergmann\CodeCoverage\Filter":0:{}');
 28
 29        $this->files = [
 30            TEST_FILES_PATH . 'BankAccount.php',
 31            TEST_FILES_PATH . 'BankAccountTest.php',
 32            TEST_FILES_PATH . 'CoverageClassExtendedTest.php',
 33            TEST_FILES_PATH . 'CoverageClassTest.php',
 34            TEST_FILES_PATH . 'CoverageFunctionParenthesesTest.php',
 35            TEST_FILES_PATH . 'CoverageFunctionParenthesesWhitespaceTest.php',
 36            TEST_FILES_PATH . 'CoverageFunctionTest.php',
 37            TEST_FILES_PATH . 'CoverageMethodOneLineAnnotationTest.php',
 38            TEST_FILES_PATH . 'CoverageMethodParenthesesTest.php',
 39            TEST_FILES_PATH . 'CoverageMethodParenthesesWhitespaceTest.php',
 40            TEST_FILES_PATH . 'CoverageMethodTest.php',
 41            TEST_FILES_PATH . 'CoverageNoneTest.php',
 42            TEST_FILES_PATH . 'CoverageNotPrivateTest.php',
 43            TEST_FILES_PATH . 'CoverageNotProtectedTest.php',
 44            TEST_FILES_PATH . 'CoverageNotPublicTest.php',
 45            TEST_FILES_PATH . 'CoverageNothingTest.php',
 46            TEST_FILES_PATH . 'CoveragePrivateTest.php',
 47            TEST_FILES_PATH . 'CoverageProtectedTest.php',
 48            TEST_FILES_PATH . 'CoveragePublicTest.php',
 49            TEST_FILES_PATH . 'CoverageTwoDefaultClassAnnotations.php',
 50            TEST_FILES_PATH . 'CoveredClass.php',
 51            TEST_FILES_PATH . 'CoveredFunction.php',
 52            TEST_FILES_PATH . 'NamespaceCoverageClassExtendedTest.php',
 53            TEST_FILES_PATH . 'NamespaceCoverageClassTest.php',
 54            TEST_FILES_PATH . 'NamespaceCoverageCoversClassPublicTest.php',
 55            TEST_FILES_PATH . 'NamespaceCoverageCoversClassTest.php',
 56            TEST_FILES_PATH . 'NamespaceCoverageMethodTest.php',
 57            TEST_FILES_PATH . 'NamespaceCoverageNotPrivateTest.php',
 58            TEST_FILES_PATH . 'NamespaceCoverageNotProtectedTest.php',
 59            TEST_FILES_PATH . 'NamespaceCoverageNotPublicTest.php',
 60            TEST_FILES_PATH . 'NamespaceCoveragePrivateTest.php',
 61            TEST_FILES_PATH . 'NamespaceCoverageProtectedTest.php',
 62            TEST_FILES_PATH . 'NamespaceCoveragePublicTest.php',
 63            TEST_FILES_PATH . 'NamespaceCoveredClass.php',
 64            TEST_FILES_PATH . 'NotExistingCoveredElementTest.php',
 65            TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php',
 66            TEST_FILES_PATH . 'source_with_ignore.php',
 67            TEST_FILES_PATH . 'source_with_namespace.php',
 68            TEST_FILES_PATH . 'source_with_oneline_annotations.php',
 69            TEST_FILES_PATH . 'source_without_ignore.php',
 70            TEST_FILES_PATH . 'source_without_namespace.php'
 71        ];
 72    }
 73
 74    /**
 75     * @covers SebastianBergmann\CodeCoverage\Filter::addFileToWhitelist
 76     * @covers SebastianBergmann\CodeCoverage\Filter::getWhitelist
 77     */
 78    public function testAddingAFileToTheWhitelistWorks()
 79    {
 80        $this->filter->addFileToWhitelist($this->files[0]);
 81
 82        $this->assertEquals(
 83            [$this->files[0]],
 84            $this->filter->getWhitelist()
 85        );
 86    }
 87
 88    /**
 89     * @covers SebastianBergmann\CodeCoverage\Filter::removeFileFromWhitelist
 90     * @covers SebastianBergmann\CodeCoverage\Filter::getWhitelist
 91     */
 92    public function testRemovingAFileFromTheWhitelistWorks()
 93    {
 94        $this->filter->addFileToWhitelist($this->files[0]);
 95        $this->filter->removeFileFromWhitelist($this->files[0]);
 96
 97        $this->assertEquals([], $this->filter->getWhitelist());
 98    }
 99
100    /**
101     * @covers  SebastianBergmann\CodeCoverage\Filter::addDirectoryToWhitelist
102     * @covers  SebastianBergmann\CodeCoverage\Filter::getWhitelist
103     * @depends testAddingAFileToTheWhitelistWorks
104     */
105    public function testAddingADirectoryToTheWhitelistWorks()
106    {
107        $this->filter->addDirectoryToWhitelist(TEST_FILES_PATH);
108
109        $whitelist = $this->filter->getWhitelist();
110        sort($whitelist);
111
112        $this->assertEquals($this->files, $whitelist);
113    }
114
115    /**
116     * @covers SebastianBergmann\CodeCoverage\Filter::addFilesToWhitelist
117     * @covers SebastianBergmann\CodeCoverage\Filter::getWhitelist
118     */
119    public function testAddingFilesToTheWhitelistWorks()
120    {
121        $facade = new \File_Iterator_Facade;
122
123        $files = $facade->getFilesAsArray(
124            TEST_FILES_PATH,
125            $suffixes = '.php'
126        );
127
128        $this->filter->addFilesToWhitelist($files);
129
130        $whitelist = $this->filter->getWhitelist();
131        sort($whitelist);
132
133        $this->assertEquals($this->files, $whitelist);
134    }
135
136    /**
137     * @covers  SebastianBergmann\CodeCoverage\Filter::removeDirectoryFromWhitelist
138     * @covers  SebastianBergmann\CodeCoverage\Filter::getWhitelist
139     * @depends testAddingADirectoryToTheWhitelistWorks
140     */
141    public function testRemovingADirectoryFromTheWhitelistWorks()
142    {
143        $this->filter->addDirectoryToWhitelist(TEST_FILES_PATH);
144        $this->filter->removeDirectoryFromWhitelist(TEST_FILES_PATH);
145
146        $this->assertEquals([], $this->filter->getWhitelist());
147    }
148
149    /**
150     * @covers SebastianBergmann\CodeCoverage\Filter::isFile
151     */
152    public function testIsFile()
153    {
154        $this->assertFalse($this->filter->isFile('vfs://root/a/path'));
155        $this->assertFalse($this->filter->isFile('xdebug://debug-eval'));
156        $this->assertFalse($this->filter->isFile('eval()\'d code'));
157        $this->assertFalse($this->filter->isFile('runtime-created function'));
158        $this->assertFalse($this->filter->isFile('assert code'));
159        $this->assertFalse($this->filter->isFile('regexp code'));
160        $this->assertTrue($this->filter->isFile(__FILE__));
161    }
162
163    /**
164     * @covers SebastianBergmann\CodeCoverage\Filter::isFiltered
165     */
166    public function testWhitelistedFileIsNotFiltered()
167    {
168        $this->filter->addFileToWhitelist($this->files[0]);
169        $this->assertFalse($this->filter->isFiltered($this->files[0]));
170    }
171
172    /**
173     * @covers SebastianBergmann\CodeCoverage\Filter::isFiltered
174     */
175    public function testNotWhitelistedFileIsFiltered()
176    {
177        $this->filter->addFileToWhitelist($this->files[0]);
178        $this->assertTrue($this->filter->isFiltered($this->files[1]));
179    }
180
181    /**
182     * @covers SebastianBergmann\CodeCoverage\Filter::isFiltered
183     * @covers SebastianBergmann\CodeCoverage\Filter::isFile
184     */
185    public function testNonFilesAreFiltered()
186    {
187        $this->assertTrue($this->filter->isFiltered('vfs://root/a/path'));
188        $this->assertTrue($this->filter->isFiltered('xdebug://debug-eval'));
189        $this->assertTrue($this->filter->isFiltered('eval()\'d code'));
190        $this->assertTrue($this->filter->isFiltered('runtime-created function'));
191        $this->assertTrue($this->filter->isFiltered('assert code'));
192        $this->assertTrue($this->filter->isFiltered('regexp code'));
193    }
194}