Skip to content

[Issue] Add exception output when fixtures fail #40579

@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #40574: Add exception output when fixtures fail


Description (*)

When running Integration Tests and using the new PHP Attributes for defining fixtures (via the DataFixture attribute) it might be that a specific data fixture class (like Magento\Catalog\Test\Fixture\Product) is producing an exception. However, because of the current code in \Magento\TestFramework\Annotation\DataFixtureSetup, the fixture is simply skipped and the exception message never is displayed. This makes it very hard to analyse failed tests.

use Magento\Catalog\Test\Fixture\Product as ProductFixture;

#[DataFixture(ProductFixture::class, ['sku' => 'simple-$$$$-001'], as: 'product')]
final class DummyTest extends TestCase
{
}

This PR adds a simple echo to display the exception message. To reproduce this, an Integration Test could be created by making use of the data fixture Magento\Catalog\Test\Fixture\Product . Next, in the original code of the fixture vendor/magento/module-catalog/Test/Fixture/Product.php, the following could be added to fake an exception:

    public function apply(array $data = []): ?DataObject
    {
        throw new \Exception('Product fixture failed with a hack');
    }

Without this PR in place, the given exception never is displayed, but the fixture is (obviously) not run either. With this PR, the fixture is still not run (obviously), however the exception is displayed.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue: ready for confirmationReported on 2.4.xIndicates original Magento version for the Issue report.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions