'Behat tests with PHPUnit assertions
I had project in symfony 4.3 which uses PHPUnit Bridge 5.0, and I wanna use assert functions in functional tests (behat). In older project I used PHPUnit package and by require_once include this functions in behat Context class like this:
require_once __DIR__.'/../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php';
But PHPUnit Bridge had this class by this path:
require_once __DIR__.'/../../bin/.phpunit/phpunit-7.5-0/src/Framework/Assert/Functions.php';
Instead of change this if I try run tests it's not pass with following error:
Fatal error: Class 'PHPUnit\Framework\Assert' not found (Behat\Testwork\Call\Exception\FatalThrowableError)
This error is caused by first use inside Functions.php class which is:
use PHPUnit\Framework\Assert;
But that class exist, because I can go to it by hand. I look in the web for some answers can be helpfull in this situation but none of these don't work. I had try use:
use PHPUnit_Framework_Assert as Assertions;
// Class which implement that what I need exist too in namespace PHPUnit\Framework with name Assert
use PHPUnit\Framework\Assert as Assertions;
What I did wrong?? Thanks for any help.
Solution 1:[1]
I'm found the solution. If someone has the same problem, just install phpunit/phpunit component and ignore warnings from PHPUnitBridge. Then use it in behat by:
use PHPUnit\Framework\Assert as Assertions;
Solution 2:[2]
What worked for me:
use PHPUnit\Framework\Assert;
// Then later, to check that the status is equal to 7
Assert::assertEquals(7, $this->status);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kris016 |
| Solution 2 | Pierre |
