Skip to content

Commit

Permalink
🔥 remove deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Oct 15, 2024
1 parent 1ba52f7 commit 55ff413
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 186 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
phpstan:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
name: PHPStan
steps:
- name: Checkout
Expand All @@ -18,26 +18,23 @@ jobs:
with:
args: analyse
cs-fixer:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
name: PHP-CS-Fixer
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Fix CS
uses: docker://oskarstark/php-cs-fixer-ga
tests:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- description: 'Symfony 6.4'
php: '8.1'
php: '8.2'
symfony: '6.4.*'
composer_option: '--prefer-lowest'
- description: 'Symfony 7.0'
php: '8.2'
symfony: '7.0.*'
- description: 'Symfony 7.1'
php: '8.3'
symfony: '7.1.*'
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
BeelabTestBundle
================
# BeelabTestBundle

[![Build Status](https://github.com/Bee-Lab/BeelabTestBundle/workflows/build/badge.svg)](https://github.com/Bee-Lab/BeelabTestBundle/actions)
[![codecov](https://codecov.io/github/Bee-Lab/BeelabTestBundle/branch/master/graph/badge.svg?token=xU1pOUeU3M)](https://codecov.io/github/Bee-Lab/BeelabTestBundle)

This bundle contains just an opinionated extension of Symfony `WebTestCase`.

Documentation
-------------

>**WARNING** if you're using version 3 of this bundle with Symfony 4.2, and you want to upgrade to
>Symfony 4.3, you need to require version 4 of this bundle. See also [UPGRADE file](UPGRADE.md).
>If you use Symfony 6, you need to pay attention to definition of service, as explained in following documentation.
## Documentation

[Read the documentation](docs/index.md)

License
-------
## License

This bundle is released under the LGPL license. See the [complete license text](LICENSE).
23 changes: 11 additions & 12 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
UPGRADE
=======
# UPGRADE

From 5.4 to 6.0
---------------
## From 6.x to 7.0

All the methods related to fixtures were removed. Instead of loading fixtures in your tests, you should
use [DAMADoctrineTestBundle ](https://github.com/dmaicher/doctrine-test-bundle).

## From 5.4 to 6.0

The `assertMailSent` method has been removed, since Swiftmailer is not supported anymore. You should use the
Symfony Mailer component instead, and the `assertEmailCount` method.
New minimum requirements are PHP 8.1 and Symfony 6.4.

The `AbstractContainerAwareFixture` was removed. Inject your dependencies directly instead of the whole container.

From 4.0 to 5.0
---------------
## From 4.0 to 5.0

A bunch of methods are now static. This is affecting you only if you're overriding such methods, since you
need to declare as static your methods too. Calling such method can be left untouched (e.g. you can still call
methods using `$this->` instead of `self::`).
Also, `$em` proteced property is now static. If you were using `$this->em`, you need to use `self::$em` instead.

From 3.0 to 4.0
---------------
## From 3.0 to 4.0

Since Symfony Test class introduced a static `$client` property, we had to move our
own non-static property. So, you need to change every occurrence of `$this->client`
Expand All @@ -30,8 +31,7 @@ Such use of parameter was deprecated in version 3, so it has been removed now.

Method `ajax` is now static. Instead of `$this->ajax(...)`, you need to use `self::ajax(...)`

From 2.x to 3.0
---------------
## From 2.x to 3.0

Since Symfony Test class introduced a static `$container` property, we had to remove our
own non-static property. So, if you were using `$this->container` in your tests, you need
Expand All @@ -42,8 +42,7 @@ Also, methods previously deprecated were removed:
* `$this->getContainer()` (use `static::$container` instead)
* `$this->getClient()` (use `$this->client` instead)

From 1.x to 2.0
---------------
## From 1.x to 2.0

If you were using the static proprerty `$admin` (with password taken from parameter `admin_password`)
for basic auth, this is not working anymore.
Expand Down
11 changes: 3 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@
}
],
"require": {
"php": "^8.1",
"doctrine/data-fixtures": "^1.6",
"php": "^8.2",
"symfony/browser-kit": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/dom-crawler": "^6.4 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4 || ^4.0",
"doctrine/lexer": "^2.1",
"doctrine/orm": "^2.16",
"mikey179/vfsstream": "^1.6.7",
"phpunit/phpunit": "^10.5 || ^11.3",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"phpunit/phpunit": "^10.6 || ^11.4",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/mime": "^6.4 || ^7.0",
"symfony/process": "^6.4 || ^7.0",
Expand All @@ -41,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "6.x-dev"
"dev-master": "7.x-dev"
}
},
"autoload": {
Expand Down
21 changes: 1 addition & 20 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
BeelabTestBundle Documentation
==============================
# BeelabTestBundle Documentation

## Installation

Expand Down Expand Up @@ -160,24 +159,6 @@ services:
array you would use for a select multiple. This allows you to easily switch between `true` and `false`
in `multiple` option of `ChoiceType`.

### Fixtures-related

⚠️️ **Warning**: these features are now deprecated and will be removed in the next major version.

* Fast fixtures load

Load fixtures simply with `$this->loadFixtures(['YourFixtureClassName', 'YourOtherFixtureClassName'])`.
Dependencies are resolved (as long as you implement `DependentFixtureInterface`), so you don't need to explicitly
load all your fixtures.

* Get entity by reference

If you need an entity in a functional test, you can get it by calling `$this->getReference('refname')`, where
`refname` is a name of a reference you used inside a fixture.
E.g., if you used `$this->addReference('foo')` or `$this->setReference('foo')` inside one of your fixtures, you
can call `$this->getReference('foo')` to retrieve the entity you created in that fixture.
⚠️️ **Warning**: this method is working only if you are loading fixtures during test execution.

### Selection-related

* Click link by data
Expand Down
85 changes: 0 additions & 85 deletions src/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
namespace Beelab\TestBundle\Test;

use Beelab\TestBundle\File\FileInjector;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as SymfonyWebTestCase;
Expand All @@ -26,9 +21,7 @@

abstract class WebTestCase extends SymfonyWebTestCase
{
protected static ?EntityManagerInterface $em = null; // @deprecated
protected static KernelBrowser $client;
private ?AbstractFixture $fixture = null;
protected static ?string $authUser = null;
protected static ?string $authPw = null;
protected static ?ContainerInterface $container = null;
Expand All @@ -43,9 +36,6 @@ protected function setUp(): void
$kernel = static::createKernel(['environment' => $environment]);
$kernel->boot();
static::$container = $kernel->getContainer();
if (static::$container->has('doctrine.orm.entity_manager')) {
self::$em = static::$container->get('doctrine.orm.entity_manager');
}
}
if (!empty(static::$authUser) && !empty(static::$authPw)) {
self::$client = static::createClient(['environment' => $environment], [
Expand All @@ -57,12 +47,6 @@ protected function setUp(): void
}
}

protected function tearDown(): void
{
self::$em?->getConnection()->close();
parent::tearDown();
}

/**
* Save request output and show it in the browser
* See https://web.archive.org/web/20190205012632/https://giorgiocefaro.com/blog/test-symfony-and-automatically-open-the-browser-with-the-response-content
Expand Down Expand Up @@ -146,41 +130,6 @@ protected static function getTxtFile(string $file = '0'): UploadedFile
return FileInjector::getTxtFile($file);
}

/**
* Load fixtures as an array of "names"
* This is inspired by https://github.com/liip/LiipFunctionalTestBundle.
*
* @param array<int, string> $fixtures e.g. ['UserData', 'OrderData']
*
* @throws \Doctrine\DBAL\Exception
* @throws \InvalidArgumentException
* @deprecated
*/
protected function loadFixtures(
array $fixtures,
string $namespace = 'App\\DataFixtures\\ORM\\',
?string $managerService = null,
bool $append = false,
): void {
trigger_error('loadFixtures is deprecated and will be removed in the next major version', E_USER_DEPRECATED);
if (null !== $managerService) {
$manager = static::$container->get($managerService);
if (!$manager instanceof EntityManagerInterface) {
throw new \InvalidArgumentException(\sprintf('The service "%s" is not an EntityManager', $manager::class));
}
} else {
$manager = self::$em;
}
$manager->getConnection()->executeStatement('SET foreign_key_checks = 0');
$loader = new Loader();
foreach ($fixtures as $fixture) {
$this->loadFixtureClass($loader, $namespace.$fixture);
}
$executor = new ORMExecutor($manager, new ORMPurger());
$executor->execute($loader->getFixtures(), $append);
$manager->getConnection()->executeStatement('SET foreign_key_checks = 1');
}

/**
* Get a form field value, from its id
* Useful for POSTs.
Expand Down Expand Up @@ -229,23 +178,6 @@ protected static function commandTest(
return $commandTester->getDisplay();
}

/**
* Get an entity by its fixtures reference name.
* @deprecated
*/
protected function getReference(string $name): object
{
trigger_error('getReference is deprecated and will be removed in the next major version', E_USER_DEPRECATED);
if (null === $this->fixture) {
throw new \RuntimeException('Load some fixtures before.');
}
if (!$this->fixture->hasReference($name)) {
throw new \InvalidArgumentException(\sprintf('Reference "%s" not found.', $name));
}

return $this->fixture->getReference($name);
}

/**
* Get a file to be used in a form.
*/
Expand Down Expand Up @@ -341,23 +273,6 @@ private static function findCheckbox(Form $form, string $name, string $value): C
throw new \InvalidArgumentException('Field not found.');
}

/**
* Load a single fixture class
* (with possible other dependent fixture classes).
* @deprecated
*/
private function loadFixtureClass(Loader $loader, string $className): void
{
$fixture = new $className();
if ($loader->hasFixture($fixture)) {
unset($fixture);

return;
}
$loader->addFixture($fixture);
$this->fixture = $fixture;
}

private static function getSession(): SessionInterface
{
if (static::$container->has('session.factory')) {
Expand Down
44 changes: 0 additions & 44 deletions tests/Test/WebTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Beelab\TestBundle\Tests;

use Beelab\TestBundle\Test\WebTestCase;
use Doctrine\Common\DataFixtures\Loader;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -215,49 +214,6 @@ public function testGetTxtFile(): void
self::assertEquals('text/plain', $file->getMimeType());
}

public function testLoadFixtureClass(): void
{
$loader = $this->getMockBuilder(Loader::class)->disableOriginalConstructor()->getMock();

// Call `loadFixtureClass` method
$method = new \ReflectionMethod(self::$mock, 'loadFixtureClass');
$method->invoke(self::$mock, $loader, FakeFixtureDependent::class);

$property = new \ReflectionProperty(WebTestCase::class, 'fixture');
$fixture = $property->getValue(self::$mock);

self::assertInstanceOf(FakeFixtureDependent::class, $fixture);
}

public function testLoadFixtures(): void
{
self::markTestIncomplete('Need to mock `loadFixtureClass` method correctly');
/*
self::$mock
->expects(self::exactly(2))
->method('loadFixtureClass');
$connection = $this->createMock('stdClass');
$eventManager = $this->createMock('stdClass');
$manager = $this->createMock(EntityManagerInterface::class);
$manager
->method('getConnection')
->willReturn($connection);
$manager
->method('getEventManager')
->willReturn($eventManager);
self::$container
->method('get')
->with('my.manager')
->willReturn($manager);
// Call `loadFixtures` method
$method = new \ReflectionMethod(self::$mock, 'loadFixtures');
$method->invoke(self::$mock, ['Fixture1', 'Fixture2'], 'My\\NameSpace\\', 'my.manager');
*/
}

public function testAjax(): void
{
self::$client
Expand Down

0 comments on commit 55ff413

Please sign in to comment.