PHPackages                             dab-libs/waesel-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. dab-libs/waesel-bundle

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

dab-libs/waesel-bundle
======================

Small library designed to simplify integration testing of Symfony applications

1.0.8(3y ago)04MITPHPPHP &gt;=8.0

Since May 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dab-libs/weasel)[ Packagist](https://packagist.org/packages/dab-libs/waesel-bundle)[ RSS](/packages/dab-libs-waesel-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

[Русская версия](README_ru.md)

Weasel
======

[](#weasel)

Weasel - is a small library designed to simplify integration testing of [Symfony](https://symfony.com/) applications.

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org/):

```
$ composer require --dev dab-libs/waesel-bundle
```

Usage
-----

[](#usage)

Suppose we want to test a pet search service by name or ID. This service implements the interface:

```
interface FindPets {
  /** @return Pet[] */
  public function do(?string $id, ?string $name): array;
}
```

It finds pets by ID, by name, or both. It returns an array of found pets, or an empty array.

To test the FindPets service, we must first create the initial state of the database. To do this, we create a fixture class by implementing the Fixture interface:

```
class FindPets_Fixture implements Fixture {
  const PET_1 = 'pet1';
  const PET_2 = 'pet2';

  public Pet $pet1;
  public Pet $pet1_2;
  public Pet $pet2;

  public function __construct(
    private CreatePet $createPet,
  ) {
  }

  public function createData(): void {
    $this->pet1 = $this->createPet->do(self::PET_1, Pet::CAT);
    $this->pet1_2 = $this->createPet->do(self::PET_1, Pet::DOG);
    $this->pet2 = $this->createPet->do(self::PET_2, Pet::CAT);
  }
}
```

The createData method of the Fixture interface is just designed to create the initial state of the database. It will be called automatically before running the test.

Let's make the fixture class a public service:

```
services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: true

  Weasel\TestBench\Tests\UseCase\Pet\FindPets\FindPets_Fixture:
```

Now let's create a test case class by inheriting it from the DbTestCase class from the Weasel library:

```
class FindPets_Test extends DbTestCase {
  /** @RequiredForTest) */
  private ?FindPets $findPets = null;
  /** @RequiredForTest) */
  private ?FindPets_Fixture $fixture = null;

  public function testFindTwoByName() {
    $pets = $this->findPets->do(null, $this->fixture::PET_1);
    self::assertTrue(in_array($this->fixture->pet1, $pets));
    self::assertTrue(in_array($this->fixture->pet1_2, $pets));
    self::assertFalse(in_array($this->fixture->pet2, $pets));
  }

  public function testFindOneByName() {
    $pets = $this->findPets->do(null, $this->fixture::PET_2);
    self::assertCount(1, $pets);
    self::assertEquals($this->fixture->pet2, $pets[0]);
  }

  public function testFindOneById() {
    $pets = $this->findPets->do($this->fixture->pet1->getId(), null);
    self::assertCount(1, $pets);
    self::assertEquals($this->fixture->pet1, $pets[0]);
  }
}
```

Next we describe fields for the FindPets service and fixtures in this class. We mark them with the @RequiredForTest annotation. Now, the FindPets service and the fixture will be automatically requested from DI container and assigned to the appropriate fields before running a test. It will be done in the setUp method of the base class. Then the method createData of the fixture class will be called. And after that, the test method will be executed, and we can use the injected services.

Why Weasel
----------

[](#why-weasel)

### Symfony services in tests without Weasel

[](#symfony-services-in-tests-without-weasel)

Almost all functionality of Symfony based applications is implemented as services. When testing, these services must be obtained from the DI container. Symfony developers advise doing it like [this](https://symfony.com/doc/current/testing.html#integration-tests):

1. initialize the Symfony kernel,
2. get the DI container using the getContainer method of the KernelTestCase class,
3. get the necessary services from the DI container.

```
class NewsletterGeneratorTest extends KernelTestCase {
    public function testSomething() {
        self::bootKernel();
        $container = static::getContainer();

        $newsletterGenerator = $container->get(NewsletterGenerator::class);
        $newsletter = $newsletterGenerator->generateMonthlyNews(...);

        $this->assertEquals('...', $newsletter->getContent());
    }
}
```

### Symfony services in tests using Weasel

[](#symfony-services-in-tests-using-weasel)

Getting a service directly from a DI container is not a natural practice for the average Symfony programmer. We get services by injecting them through constructor parameters or through setters.

The Weasel library allows us to get services by simply describing them as fields in the test case class and annotating them with the @RequiredForTest annotation:

```
class FindPets_Test extends DbTestCase {
  /** @RequiredForTest) */
  private ?FindPets $findPets = null;
  /** @RequiredForTest) */
  private ?FindPets_Fixture $fixture = null;

  public function testFindTwoByName() {
    ...
  }

  ...
}
```

This saves the programmer from having to explicitly access the DI container and makes working with services simple and familiar. Now a programmer can focus on writing tests without being distracted by writing the same type of code to get services from the DI container.

Weasel classes
--------------

[](#weasel-classes)

The Weasel library provides several base classes for writing integration and functional tests:

- KernelTestCase - for integration tests without using a database
- DbTestCase - for integration tests using a database
- WebTestCase - for functional tests without using a database
- WebDbTestCase - for functional tests using a database

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

1459d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbba14673150653380708cc233f90a8da12da8a034771b2a63ab3c84056a9046?d=identicon)[dab-libs](/maintainers/dab-libs)

---

Top Contributors

[![dab-libs](https://avatars.githubusercontent.com/u/3809287?v=4)](https://github.com/dab-libs "dab-libs (19 commits)")

---

Tags

phpsymfonytesttesting

### Embed Badge

![Health badge](/badges/dab-libs-waesel-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/dab-libs-waesel-bundle/health.svg)](https://phpackages.com/packages/dab-libs-waesel-bundle)
```

###  Alternatives

[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M774](/packages/typo3-testing-framework)[shopsys/http-smoke-testing

HTTP smoke test case for testing all configured routes in your Symfony project

68258.7k1](/packages/shopsys-http-smoke-testing)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)[pierstoval/smoke-testing

Smoke testing automator for Symfony applications

4032.6k](/packages/pierstoval-smoke-testing)[liorchamla/symfony-test-helpers

Provides cool tools to make testing over symfony smoothie and great !

222.2k](/packages/liorchamla-symfony-test-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
