diff --git a/.circleci/config.yml b/.circleci/config.yml index 18847d3..c35a017 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,50 +1,49 @@ -version: 2 +version: 2.1 + +executors: + php83: + docker: + - image: skpr/php-cli:8.3-v2-latest workflows: - version: 2 build: jobs: - - build_lowest - - build_highest - -defaults: &defaults - docker: - - image: previousnext/php-apache:7.2-3.x-dev - working_directory: /data - steps: - - checkout - - restore_cache: - keys: - - deps-{{ arch }} - - run: - name: "Install Dependencies" - command: composer update --prefer-dist --no-progress --no-suggest --no-interaction ${PREFER_LOWEST} - - save_cache: - key: deps-{{ arch }} - paths: - - vendor - - run: - name: "Lint" - command: ./bin/phpcs - - run: - name: "Test" - command: | - mkdir -p ~/phpunit - ./bin/phpunit --testsuite unit --log-junit ~/phpunit/phpunit.xml - - store_test_results: - path: ~/phpunit - - store_artifacts: - path: ~/phpunit + - build: + matrix: + parameters: + php: ["php83"] + composer-opts: ["", "--prefer-lowest"] jobs: - build_lowest: - <<: *defaults - docker: - - image: previousnext/php-apache:7.1-3.x-dev - - environment: - - PREFER_LOWEST: --prefer-lowest - build_highest: - <<: *defaults - environment: - - PREFER_LOWEST: '' + build: + parameters: + php: + type: executor + composer-opts: + type: string + executor: << parameters.php >> + working_directory: /data + steps: + - checkout + - restore_cache: + keys: + - deps-{{ arch }} + - run: + name: "Install Dependencies" + command: composer update --prefer-dist --no-progress --no-interaction << parameters.composer-opts >> + - save_cache: + key: deps-{{ arch }} + paths: + - vendor + - run: + name: "Lint" + command: ./bin/phpcs --runtime-set testVersion 8.0- + - run: + name: "Test" + command: | + mkdir -p ~/phpunit + ./bin/phpunit --log-junit ~/phpunit/phpunit.xml + - store_test_results: + path: ~/phpunit + - store_artifacts: + path: ~/phpunit diff --git a/.gitignore b/.gitignore index 9902d7b..6342d02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin /vendor +/.phpunit.result.cache /composer.lock diff --git a/composer.json b/composer.json index d4b3162..73ec539 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "previousnext/phpunit-finder", "description": "PHP lib for finding and outputting all tests from a phpunit.xml config file.", + "keywords": ["testing"], "license": "GPL-2.0-or-later", "authors": [ { @@ -13,12 +14,14 @@ } ], "require": { - "php": "^7.1", - "phpunit/phpunit": "^6.5", - "symfony/console": "^3.4" + "php": "^8.1", + "phpunit/phpunit": "^10.5", + "symfony/console": "^6.4||^7" }, "require-dev": { - "drupal/coder": ">=8.2.12" + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "drupal/coder": "~8.3.12", + "phpcompatibility/php-compatibility": "^9.3" }, "autoload": { "psr-4": {"PhpUnitFinder\\": "src/"} @@ -32,6 +35,9 @@ "preferred-install": { "*": "dist" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpcs.xml b/phpcs.xml index 7de9f55..e786749 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,26 +1,16 @@ - - PHP CodeSniffer configuration for PHPUnit Finder - + + PHP Codesniffer configuration. ./src - ./tests - + ./tests/bootstrap.php - - - - - - - + + + + + + + + diff --git a/phpunit-finder b/phpunit-finder index 5bf6278..5ab3c5c 100755 --- a/phpunit-finder +++ b/phpunit-finder @@ -5,10 +5,22 @@ * Console application for PHPUnit Finder. */ -require __DIR__ . '/../../autoload.php'; +$autoload = [ + __DIR__ . '/vendor/autoload.php', + dirname(__DIR__, 1) . '/vendor/autoload.php', + dirname(__DIR__, 2) . '/vendor/autoload.php', + dirname(__DIR__, 1) . '/autoload.php', + dirname(__DIR__, 2) . '/autoload.php', +]; +foreach ($autoload as $file) { + if (file_exists($file)) { + require $file; + break; + } +} const APP_NAME = 'PHPUnit Finder'; -const VERSION = '0.0.1'; +const VERSION = '2.x-dev'; use PhpUnitFinder\FinderCommand; use Symfony\Component\Console\Application; diff --git a/phpunit.xml b/phpunit.xml index 4b29e2e..86e75cb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,15 +1,10 @@ - - + @@ -21,19 +16,15 @@ ./tests/Unit - - ./tests/Functional - - - + + ./src - - - ./ - ./ - - - + + + ./ + ./ + + diff --git a/src/FinderCommand.php b/src/FinderCommand.php index 770e9c2..1a8304c 100644 --- a/src/FinderCommand.php +++ b/src/FinderCommand.php @@ -3,8 +3,10 @@ namespace PhpUnitFinder; use PHPUnit\Framework\TestCase; -use PHPUnit\Util\Configuration; -use ReflectionClass; +use PHPUnit\TextUI\CliArguments\Builder; +use PHPUnit\TextUI\Configuration\Registry; +use PHPUnit\TextUI\XmlConfiguration\Loader; +use PHPUnit\TextUI\XmlConfiguration\TestSuiteMapper; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -28,29 +30,38 @@ protected function configure() { /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $configFile = $input->getOption('config-file'); $bootstrap = $input->getOption('bootstrap-file'); include_once $bootstrap; $testSuites = $input->getArgument('test-suite'); - - $config = Configuration::getInstance($configFile); - if (empty($testSuites)) { - $testSuites = $config->getTestSuiteNames(); - } $testFilenames = []; - foreach ($testSuites as $suiteName) { - $suite = $config->getTestSuiteConfiguration($suiteName); - foreach (new \RecursiveIteratorIterator($suite->getIterator()) as $test) { + + $config = (new Loader())->load($configFile); + + Registry::init( + (new Builder)->fromParameters([]), + $config, + ); + + foreach ($config->testSuite() as $suite) { + if ($testSuites && !in_array($suite->name(), $testSuites, TRUE)) { + continue; + } + $testSuite = (new TestSuiteMapper())->map($config->filename(), $config->testSuite(), $suite->name(), ''); + foreach (new \RecursiveIteratorIterator($testSuite) as $test) { if ($test instanceof TestCase) { - $testFilenames[] = ((new ReflectionClass($test))->getFileName()); + $testFilenames[] = ((new \ReflectionClass($test))->getFileName()); } } } + $testFilenames = array_unique($testFilenames); foreach ($testFilenames as $testFilename) { $output->writeln($testFilename); } + + return 0; } } diff --git a/tests/Unit/FinderTest.php b/tests/Unit/FinderTest.php new file mode 100644 index 0000000..2a32874 --- /dev/null +++ b/tests/Unit/FinderTest.php @@ -0,0 +1,33 @@ +execute([ + '--config-file' => dirname(__DIR__) . '/fixtures/phpunit.xml' + ]); + $output = $command->getDisplay(); + $this->assertNotNull($output); + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString('TestUnitTest.php', $output); + $this->assertStringContainsString('TestFunctionalTest.php', $output); + return; + } + $this->assertContains('TestUnitTest.php', $output); + $this->assertContains('TestFunctionalTest.php', $output); + } + +} diff --git a/tests/Unit/StubTest.php b/tests/Unit/StubTest.php deleted file mode 100644 index 105cc7e..0000000 --- a/tests/Unit/StubTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(TRUE); - } - -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7ddf755..0bf42f5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -4,9 +4,6 @@ * @file * Boostrap for PHPUnit. */ - -assert_options(ASSERT_ACTIVE, FALSE); - $autoloader = __DIR__ . '/../vendor/autoload.php'; $loader = require $autoloader; diff --git a/tests/fixtures/phpunit.xml b/tests/fixtures/phpunit.xml new file mode 100644 index 0000000..1fcab63 --- /dev/null +++ b/tests/fixtures/phpunit.xml @@ -0,0 +1,33 @@ + + + + + + + ./src + + + ./ + ./ + + + + + + + + + + + + ./tests/Unit + + + ./tests/Functional + + + + diff --git a/tests/fixtures/tests/Functional/TestFunctionalTest.php b/tests/fixtures/tests/Functional/TestFunctionalTest.php new file mode 100644 index 0000000..3ee4ed8 --- /dev/null +++ b/tests/fixtures/tests/Functional/TestFunctionalTest.php @@ -0,0 +1,19 @@ +addToAssertionCount(1); + } + +} diff --git a/tests/fixtures/tests/Unit/TestUnitTest.php b/tests/fixtures/tests/Unit/TestUnitTest.php new file mode 100644 index 0000000..90f0829 --- /dev/null +++ b/tests/fixtures/tests/Unit/TestUnitTest.php @@ -0,0 +1,19 @@ +addToAssertionCount(1); + } + +}