diff --git a/.ddev/config.wunderio.yaml b/.ddev/config.wunderio.yaml index 6548d872..8d62501e 100644 --- a/.ddev/config.wunderio.yaml +++ b/.ddev/config.wunderio.yaml @@ -13,7 +13,7 @@ hooks: # @todo We could potentially make this work from recognizing the command. - exec: | if ! command -v wdr-core &> /dev/null; then - ln -s ${HOME}/wunderio/core/wdr-core.sh /usr/local/bin/wdr-core + sudo ln -s ${HOME}/wunderio/core/wdr-core.sh /usr/local/bin/wdr-core fi # Run once start hook if needed if [ ! -f "/mnt/wdr-hooks/ddev_web_post_start_once" ]; then diff --git a/composer.json b/composer.json index 79d2d6c9..168b3455 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ }, "require-dev": { "drupal/core-dev": "^11.4", - "wunderio/code-quality": "^3.0" + "wunderio/code-quality": "dev-GH-126-php" }, "conflict": { "drupal/drupal": "*" diff --git a/phpunit.xml b/phpunit.xml index 796cbbc7..7500a113 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -49,19 +49,12 @@ - ./web/core/includes - ./web/core/lib - ./web/core/modules - ./web/core/modules - ./web/core/sites + ./web/modules/custom + ./web/themes/custom - ./web/core/modules/*/src/Tests - ./web/core/modules/*/tests - ./web/core/modules/*/src/Tests - ./web/core/modules/*/tests - ./web/core/modules/*/*/src/Tests - ./web/core/modules/*/*/tests + ./web/modules/custom/*/tests + ./web/themes/custom/*/tests diff --git a/web/modules/custom/phpunit_example/phpunit_example.info.yml b/web/modules/custom/phpunit_example/phpunit_example.info.yml index 4a9eea2d..52abee45 100644 --- a/web/modules/custom/phpunit_example/phpunit_example.info.yml +++ b/web/modules/custom/phpunit_example/phpunit_example.info.yml @@ -2,6 +2,4 @@ name: PHPUnit Example type: module description: Demonstrates how to use PHPUnit-based tests. package: Example modules -core_version_requirement: ^10 || ^11 -dependencies: - - drupal:node +core_version_requirement: ^11 diff --git a/web/modules/custom/phpunit_example/phpunit_example.module b/web/modules/custom/phpunit_example/phpunit_example.module index b02383de..aeeb7b02 100644 --- a/web/modules/custom/phpunit_example/phpunit_example.module +++ b/web/modules/custom/phpunit_example/phpunit_example.module @@ -9,7 +9,7 @@ * @defgroup phpunit_example Example: PHPUnit * @ingroup examples * @{ - * This example demonstrates PHPUnit for Drupal 8 unit testing. + * This example demonstrates PHPUnit for Drupal unit testing. */ /** diff --git a/web/modules/custom/phpunit_example/src/AddClass.php b/web/modules/custom/phpunit_example/src/AddClass.php index c60481ad..5443c79f 100644 --- a/web/modules/custom/phpunit_example/src/AddClass.php +++ b/web/modules/custom/phpunit_example/src/AddClass.php @@ -1,5 +1,7 @@ assertEquals($sut->add(2, 3), 5); + $this->assertEquals(5, $sut->add(2, 3)); } + #[DataProvider('addDataProvider')] /** * Test AddClass::add() with a data provider method. * - * This method is very similar to testAdd(), but uses a data provider method - * to test with a wider range of data. + * This method is very similar to testAdd(), but uses a data provider + * method to test with a wider range of data. * * You can tell PHPUnit which method is the data provider using the - * '@dataProvider' annotation. + * '#[DataProvider]' attribute. * * The data provider method just returns a big array of arrays of arguments. * That is, for each time you want this test method run, the data provider @@ -80,36 +86,29 @@ public function testAdd() { * tests 'good' data. When combined with testAddWithBadDataProvider(), * we get a better picture of the behavior of the method under test. * - * @dataProvider addDataProvider - * * @see self::addDataProvider() */ - public function testAddWithDataProvider($expected, $a, $b) { + public function testAddWithDataProvider(int|float $expected, int|float $a, int|float $b): void { $sut = new AddClass(); $this->assertEquals($expected, $sut->add($a, $b)); } + #[DataProvider('addBadDataProvider')] /** * Test AddClass::add() with data that should throw an exception. * * This method is similar to testAddWithDataProvider(), but the data * provider gives us data that should throw an exception. * - * This test uses the setExpectedException() method to tell PHPUnit that - * a thrown exception should pass the test. You specify a - * fully-qualified exception class name. If you specify \Exception, PHPUnit - * will pass any exception, whereas a more specific subclass of \Exception - * will require that exception type to be thrown. - * - * Alternately, you can use try and catch blocks with assertions in order - * to test exceptions. We won't demonstrate that here; it's a much better - * idea to test your exceptions with setExpectedException(). - * - * @dataProvider addBadDataProvider + * This test uses the expectException() method to tell PHPUnit that a + * thrown exception should pass the test. You specify a fully-qualified + * exception class name. If you specify \Exception, PHPUnit will pass any + * exception, whereas a more specific subclass of \Exception will require + * that exception type to be thrown. * * @see self::addBadDataProvider() */ - public function testAddWithBadDataProvider($a, $b) { + public function testAddWithBadDataProvider(mixed $a, mixed $b): void { $sut = new AddClass(); $this->expectException(\InvalidArgumentException::class); $sut->add($a, $b); @@ -135,7 +134,7 @@ public function testAddWithBadDataProvider($a, $b) { * * @see self::testAddWithDataProvider() */ - public static function addDataProvider() { + public static function addDataProvider(): array { return [ [5, 2, 3], [50, 20, 30], @@ -154,7 +153,7 @@ public static function addDataProvider() { * * @see self::testAddWithBadDataProvider() */ - public static function addBadDataProvider() { + public static function addBadDataProvider(): array { $bad_data = []; // Set up an array with data that should cause add() // to throw an exception.