No output if one of many tests throws exception
Closed this issue · 2 comments
I have a test class containing multiple tests.
Two of those tests us the same Mockery::mock(SAME_CLASS).
As the TestCase does not tear down after each test (see markhuot/craft-pest#102) it throws an exception, that the mock can not be re-initialized.
These are the tests:
it('first test', function () {
PublicApi::getInstance()->set(
'some-class',
$mock = Mockery::mock(PublicApi::getInstance()->some-class)
);
$this->post('/api/v1/forms/contact', $this->validData)
->assertOk();
// Some assertions
});
it('second test', function () {
PublicApi::getInstance()->set(
'some-class',
$mock = Mockery::mock(PublicApi::getInstance()->some-class)
);
$this->post('/api/v1/forms/contact', $this->validData)
->assertOk();
// Some other assertions
});
When i now run ddev craft pest
running all tests, then the second test would throw an exception (which it did using https://github.com/markhuot/craft-pest) but now it just does not output anything.
Can you confirm this is still an issue? I'm not seeing it with this simple repro,
it('mocks a class', function () {
$mock = mock(\craft\services\Elements::class)
->shouldReceive('saveElement')
->once()
->getMock();
$mock->saveElement(new \craft\elements\Entry());
})->repeat(2);
I'm seeing success even when using a module container like this,
it('mocks a class', function () {
$mock = Mockery::mock(\craft\services\Elements::class);
\Craft::$app->set('some-class', $mock);
expect(\Craft::$app->get('some-class'))->toBe($mock);
})->repeat(2);
Feel free to re-open if you're still seeing this.
HI @markhuot,
I am using "markhuot/craft-pest": "^2.0.0"
It seems that this issue occurs in my project when in the application code something goes so wrong, that it exits with the status code 255.
So when adding this test to my test file I get the exact same output, namely: Failed to run craft pest: exit status 255
it('exit 1', function () {
exit(255);
});
As this does not have anything to do with pest, I would leave this issue closed.
But thanks for looking into it and thanks for craft-pest 😊