Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests fail under Drupal 10.1 #547

Closed
JohnAlbin opened this issue Oct 10, 2023 · 5 comments
Closed

Unit tests fail under Drupal 10.1 #547

JohnAlbin opened this issue Oct 10, 2023 · 5 comments
Labels
area: next module bug Something isn't working tooling tooling changes (CI, tests, etc.); no code changes
Milestone

Comments

@JohnAlbin
Copy link
Collaborator

Package containing the bug

next (Drupal module)

Describe the bug

When running the next module's unit tests with Drupal 10.1, there are 3 failing tests.

Expected behavior

Tests should pass under 10.1 (and under 10.0 and 9.5).

Steps to reproduce:

  1. Install drupal/core-dev 10.1 in ~/drupal
  2. Copy next into ~/drupal/modules/next
  3. From ~/drupal, run: ./vendor/bin/phpunit -c ./web modules/next
  4. 😢

Additional context

Here's the output when running phpunit:

% ../vendor/bin/phpunit -c core modules/next
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

Testing ~/drupal/web/modules/next
...............E....EE......                                      28 / 28 (100%)

Time: 00:55.923, Memory: 12.00 MB

There were 3 errors:

1) Drupal\Tests\next\Kernel\Plugin\PathRevalidatorTest::testRevalidate
PHPUnit\Framework\Exception: TypeError: Double\ResponseInterface\P2::getStatusCode(): Return value must be of type int, null returned in ~/drupal/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(44) : eval()'d code:6
Stack trace:
#0 ~/drupal/web/modules/next/src/Plugin/Next/Revalidator/Path.php(106): Double\ResponseInterface\P2->getStatusCode()
#1 ~/drupal/web/modules/next/src/EventSubscriber/EntityActionEventRevalidateSubscriber.php(33): Drupal\next\Plugin\Next\Revalidator\Path->revalidate(Object(Drupal\next\Event\EntityActionEvent))
#2 [internal function]: Drupal\next\EventSubscriber\EntityActionEventRevalidateSubscriber->onAction(Object(Drupal\next\Event\EntityActionEvent), 'next.entity.act...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#3 ~/drupal/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\next\Event\EntityActionEvent), 'next.entity.act...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#4 ~/drupal/web/modules/next/next.module(98): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\next\Event\EntityActionEvent), 'next.entity.act...')
#5 ~/drupal/web/core/includes/bootstrap.inc(538): _next_dispatch_entity_action_event(Object(Drupal\next\Event\EntityActionEvent))
#6 ~/drupal/web/modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php(89): _drupal_shutdown_function()
#7 ~/drupal/web/sites/simpletest/TestCase.php(1614): Drupal\Tests\next\Kernel\Plugin\PathRevalidatorTest->testRevalidate()
#8 ~/drupal/web/sites/simpletest/TestCase.php(1220): PHPUnit\Framework\TestCase->runTest()
#9 ~/drupal/vendor/phpunit/phpunit/src/Framework/TestResult.php(728): PHPUnit\Framework\TestCase->runBare()
#10 ~/drupal/web/sites/simpletest/TestCase.php(970): PHPUnit\Framework\TestResult->run(Object(Drupal\Tests\next\Kernel\Plugin\PathRevalidatorTest))
#11 Standard input code(67): PHPUnit\Framework\TestCase->run(Object(PHPUnit\Framework\TestResult))
#12 Standard input code(127): __phpunit_run_isolated_test()
#13 {main}

Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in ~/drupal/web/core/lib/Drupal.php:169
Stack trace:
#0 ~/drupal/web/core/lib/Drupal.php(197): Drupal::getContainer()
#1 ~/drupal/web/modules/next/next.module(98): Drupal::service('event_dispatche...')
#2 ~/drupal/web/core/includes/bootstrap.inc(538): _next_dispatch_entity_action_event(Object(Drupal\next\Event\EntityActionEvent))
#3 [internal function]: _drupal_shutdown_function()
#4 {main}

~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:144
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:97

2) Drupal\Tests\next\Kernel\Plugin\SimpleOauthPreviewUrlGeneratorTest::testValidateForInvalidBody with data set #2 (array('/node/1', 1696965726), 'Field 'scope' is missing')
PHPUnit\Framework\Exception: Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in ~/drupal/web/core/lib/Drupal.php:169
Stack trace:
#0 ~/drupal/web/core/lib/Drupal.php(197): Drupal::getContainer()
#1 ~/drupal/web/modules/next/next.module(98): Drupal::service('event_dispatche...')
#2 ~/drupal/web/core/includes/bootstrap.inc(538): _next_dispatch_entity_action_event(Object(Drupal\next\Event\EntityActionEvent))
#3 [internal function]: _drupal_shutdown_function()
#4 {main}

~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:144
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:97

3) Drupal\Tests\next\Kernel\Plugin\SimpleOauthPreviewUrlGeneratorTest::testValidateForInvalidBody with data set #3 (array('/node/1', 1696965726, 'llama'), 'Field 'secret' is missing')
PHPUnit\Framework\Exception: Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in ~/drupal/web/core/lib/Drupal.php:169
Stack trace:
#0 ~/drupal/web/core/lib/Drupal.php(197): Drupal::getContainer()
#1 ~/drupal/web/modules/next/next.module(98): Drupal::service('event_dispatche...')
#2 ~/drupal/web/core/includes/bootstrap.inc(538): _next_dispatch_entity_action_event(Object(Drupal\next\Event\EntityActionEvent))
#3 [internal function]: _drupal_shutdown_function()
#4 {main}

~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/Framework/TestSuite.php:684
~/drupal/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:144
~/drupal/vendor/phpunit/phpunit/src/TextUI/Command.php:97

ERRORS!
Tests: 28, Assertions: 288, Errors: 3.
@JohnAlbin JohnAlbin added bug Something isn't working area: next module tooling tooling changes (CI, tests, etc.); no code changes labels Oct 10, 2023
@JohnAlbin JohnAlbin added this to the next 2.0.0 milestone Nov 21, 2023
@mglaman
Copy link
Contributor

mglaman commented Dec 7, 2023


2) Drupal\Tests\next\Kernel\Plugin\SimpleOauthPreviewUrlGeneratorTest::testValidateForInvalidBody with data set #2 (array('/node/1', 1696965726), 'Field 'scope' is missing')
PHPUnit\Framework\Exception: Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in ~/drupal/web/core/lib/Drupal.php:169
Stack trace:
#0 ~/drupal/web/core/lib/Drupal.php(197): Drupal::getContainer()
#1 ~/drupal/web/modules/next/next.module(98): Drupal::service('event_dispatche...')
#2 ~/drupal/web/core/includes/bootstrap.inc(538): _next_dispatch_entity_action_event(Object(Drupal\next\Event\EntityActionEvent))
#3 [internal function]: _drupal_shutdown_function()
#4 {main}

This would/will be fixed with #606

@mglaman
Copy link
Contributor

mglaman commented Dec 7, 2023

Then for PathRevalidatorTest,

$client->request('GET', 'http://blog.com/api/revalidate?slug=/node/2')->shouldBeCalled();

These prophecy mocks need to return a response object to fix

TypeError: Double\ResponseInterface\P2::getStatusCode(): Return value must be of type int, null returned

@JohnAlbin
Copy link
Collaborator Author

Yay! The first 2 failures were indeed fixed with #606.

@mglaman
Copy link
Contributor

mglaman commented Dec 12, 2023

@JohnAlbin if you want a hand with those last two, I can help out – like a PR against 547-ci-matrix-d10-1.

But the fix should look something like

    $client->request('GET', 'http://blog.com/api/revalidate?slug=/node/2')
      ->shouldBeCalled()
      ->willReturn(new \GuzzleHttp\Psr7\Response());

EDIT: may need to create a method for helping return those mocks, since there are a lot of them

JohnAlbin added a commit that referenced this issue Dec 13, 2023
@JohnAlbin
Copy link
Collaborator Author

@mglaman Your suggestion worked perfectly. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: next module bug Something isn't working tooling tooling changes (CI, tests, etc.); no code changes
Projects
None yet
Development

No branches or pull requests

2 participants