Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⬆️ update PHPUnit to 9.6, DMA Extension 6.7 and upgrade tests #3570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ compose.override.yaml
###> phpunit/phpunit ###
/phpunit.xml
/.phpunit.result.cache
/.phpunit.cache
###< phpunit/phpunit ###

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"bobdenotter/configuration-notices": "^1.2",
"bobdenotter/weatherwidget": "^1.1",
"bolt/newswidget": "^1.3",
"dama/doctrine-test-bundle": "^6.6.0",
"dama/doctrine-test-bundle": "^6.0",
"nyholm/psr7": "^1.4",
"ondram/ci-detector": "^4.1",
"php-http/curl-client": "^2.2",
Expand All @@ -109,7 +109,7 @@
"phpstan/phpstan": "^1.2.0",
"phpstan/phpstan-doctrine": "^1.0",
"phpstan/phpstan-symfony": "^1.0.1",
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^9.6",
"se/selenium-server-standalone": "^3.141",
"symfony/browser-kit": "^5.4",
"symfony/css-selector": "^5.4",
Expand All @@ -124,7 +124,8 @@
"composer/package-versions-deprecated": true,
"drupol/composer-packages": true,
"symfony/flex": true,
"php-http/discovery": true
"php-http/discovery": true,
"dealerdirect/phpcodesniffer-composer-installer": false
}
},
"extra": {
Expand Down
70 changes: 31 additions & 39 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="phpunit.bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" force="true"/>
<env name="KERNEL_CLASS" value="Bolt\Kernel"/>
<env name="APP_ENV" value="test" force="true"/>
<env name="APP_DEBUG" value="1" force="true"/>
<env name="APP_SECRET" value="5a79a1c866efef9ca1800f971d689f3e"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="7.2"/>
<!-- define your env variables for the test env here -->

<!-- ###+ doctrine/doctrine-bundle ### -->
<env name="DATABASE_URL" value="sqlite::memory:" force="true"/>
<!-- ###- doctrine/doctrine-bundle ### -->
<!-- ###+ nelmio/cors-bundle ### -->
<env name="CORS_ALLOW_ORIGIN" value="^https?://localhost(:[0-9]+)?$"/>
<!-- ###- nelmio/cors-bundle ### -->

<!-- ###+ php-translation/loco-adapter ### -->
<env name="LOCO_PROJECT_API_KEY" value=""/>
<!-- ###- php-translation/loco-adapter ### -->

<!-- ###+ symfony/mailer ### -->
<!-- MAILER_DSN=smtp://localhost -->
<!-- ###- symfony/mailer ### -->
</php>

<testsuites>
<testsuite name="Bolt Test Suite">
<directory>tests/php/</directory>
</testsuite>
</testsuites>

<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>

bootstrap="phpunit.bootstrap.php">
<php>
<ini name="error_reporting" value="-1" force="true"/>
<env name="KERNEL_CLASS" value="Bolt\Kernel"/>
<env name="APP_ENV" value="test" force="true"/>
<env name="APP_DEBUG" value="1" force="true"/>
<env name="APP_SECRET" value="5a79a1c866efef9ca1800f971d689f3e"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="10.5"/>
<!-- define your env variables for the test env here -->
<!-- ###+ doctrine/doctrine-bundle ### -->
<env name="DATABASE_URL" value="sqlite::memory:" force="true"/>
<!-- ###- doctrine/doctrine-bundle ### -->
<!-- ###+ nelmio/cors-bundle ### -->
<env name="CORS_ALLOW_ORIGIN" value="^https?://localhost(:[0-9]+)?$"/>
<!-- ###- nelmio/cors-bundle ### -->
<!-- ###+ php-translation/loco-adapter ### -->
<env name="LOCO_PROJECT_API_KEY" value=""/>
<!-- ###- php-translation/loco-adapter ### -->
<!-- ###+ symfony/mailer ### -->
<!-- MAILER_DSN=smtp://localhost -->
<!-- ###- symfony/mailer ### -->
</php>
<testsuites>
<testsuite name="Bolt Test Suite">
<directory>tests/php/</directory>
</testsuite>
</testsuites>
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
</extensions>
</phpunit>
6 changes: 0 additions & 6 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@
"phpunit/php-timer": {
"version": "2.1.2"
},
"phpunit/php-token-stream": {
"version": "3.1.1"
},
"phpunit/phpunit": {
"version": "4.7",
"recipe": {
Expand Down Expand Up @@ -493,9 +490,6 @@
"sebastian/recursion-context": {
"version": "3.0.0"
},
"sebastian/resource-operations": {
"version": "2.0.1"
},
"sebastian/type": {
"version": "1.1.4"
},
Expand Down
11 changes: 9 additions & 2 deletions tests/php/Menu/FrontendMenuBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ protected function setUp(): void
$this->request->attributes = $this->createMock(ParameterBag::class);
$this->request->attributes
->method('get')
->withConsecutive(['_route'], ['_route_params'])
->willReturn('homepage_locale', []);
->willReturnCallback(function ($param) {
if ($param === '_route') {
return 'homepage';
}
if ($param === '_route_params') {
return [];
}
return null;
});
$this->app = $this->createMock(AppVariable::class);
$this->app->method('getRequest')->willReturn($this->request);
$this->twig->method('getGlobals')->willReturn(['app' => $this->app]);
Expand Down
100 changes: 63 additions & 37 deletions tests/php/Twig/ContentExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ protected function setUp(): void
public function testTitle(): void
{
$this->definition->method('has')
->withConsecutive(['title_format'])
->willReturn(true);
->willReturnCallback(fn($param) => $param === 'title_format');
$this->definition->method('get')
->withConsecutive(['title_format'])
->willReturn('{number}: {title}');
->willReturnCallback(fn($param) => $param === 'title_format' ? '{number}: {title}' : null);
$this->content->method('getId')
->willReturn(1);
$this->content->method('hasField')
->withConsecutive(['number'], ['title'])
->willReturnOnConsecutiveCalls(false, true);
->willReturnCallback(function ($param) {
if ($param === 'number') {
return false;
}
if ($param === 'title') {
return true;
}
return false;
});
$this->content->method('getField')
->withConsecutive(['title'])
->willReturn($this->field);
->willReturnCallback(fn($param) => $param === 'title' ? $this->field : null);
$this->field->method('isTranslatable')
->willReturn(false);
$this->field->method('__toString')
Expand All @@ -70,17 +74,21 @@ public function testTitle(): void
public function testTitleFields(): void
{
$this->definition->method('has')
->withConsecutive(['title_format'])
->willReturn(true);
->willReturnCallback(fn($param) => $param === 'title_format');
$this->definition->method('get')
->withConsecutive(['title_format'])
->willReturn('{number}: {title}');
->willReturnCallback(fn($param) => $param === 'title_format' ? '{number}: {title}' : null);
$this->content->method('getId')
->willReturn(1);
$this->content->method('hasField')
->withConsecutive(['number'], ['title'])
->willReturnOnConsecutiveCalls(false, true);

->willReturnCallback(function ($param) {
if ($param === 'number') {
return false;
}
if ($param === 'title') {
return true;
}
return false;
});
$this->assertSame(['number', 'title'], $this->extension->getTitleFieldsNames($this->content));
}

Expand All @@ -97,8 +105,7 @@ public function testContentImage(): void
$this->assertNull($this->extension->getImage($this->content));

$imagefield->method('get')
->withConsecutive(['filename'])
->willReturn('example.jpg');
->willReturnCallback(fn($param) => $param === 'filename' ? 'example.jpg' : null);
$this->assertSame($imagefield, $this->extension->getImage($this->content));
}

Expand All @@ -108,8 +115,7 @@ public function testContentImageWithImagelist(): void
$field2 = $this->createMock(Field::class);
$image1 = $this->createMock(ImageField::class);
$image1->method('get')
->withConsecutive(['filename'])
->willReturn('testimage.jpg');
->willReturnCallback(fn($param) => $param === 'filename' ? 'testimage.jpg' : null);
$image2 = $this->createMock(ImageField::class);
$imagelist = $this->createMock(ImagelistField::class);
$field3 = $this->createMock(Field::class);
Expand All @@ -129,23 +135,37 @@ public function testExcerptOnString(): void
public function testExceptFromFormatShort(): void
{
$this->definition->method('get')
->withConsecutive(['excerpt_format'])
->willReturn('{subheading}: {body}');
->willReturnCallback(fn($param) => $param === 'excerpt_format' ? '{subheading}: {body}' : null);

$this->content->method('hasField')
->withConsecutive(['subheading'], ['body'])
->willReturnOnConsecutiveCalls(true, true);
->willReturnCallback(function ($param) {
if ($param === 'subheading' || $param === 'body') {
return true;
}
return false;
})

$field1 = $this->createMock(Field::class);
$field2 = $this->createMock(Field::class);
$field1->method('__toString')->willReturn("In this week's news");
$field2->method('__toString')->willReturn('Bolt 4 is pretty awesome.');
$this->content->method('getField')
->withConsecutive(['subheading'], ['body'])
->willReturnOnConsecutiveCalls($field1, $field2);
->willReturnCallback(function ($param) use($field1, $field2) {
if ($param === 'subheading') {
return $field1;
}
if ($param === 'body') {
return $field2;
}
return null;
});
$this->definition->method('has')
->withConsecutive(['excerpt_format'], ['subheading'], ['body'])
->willReturn(true);
->willReturnCallback(function ($param) {
if ($param === 'excerpt_format' || $param === 'subheading' || $param === 'body') {
return true;
}
return false;
});
$this->content->method('getId')
->willReturn(1);

Expand All @@ -155,27 +175,32 @@ public function testExceptFromFormatShort(): void
public function testExceptFromFormatFull(): void
{
$this->definition->method('get')
->withConsecutive(['excerpt_format'])
->willReturn('{subheading}: {body}');
->willReturnCallback(fn($param) => $param === 'excerpt_format' ? '{subheading}: {body}' : null);

$this->content->method('hasField')
->withConsecutive(['subheading'], ['body'])
->willReturnOnConsecutiveCalls(true, true);
->willReturnCallback(fn ($param) => $param === 'subheading' || $param === 'body');

$field1 = $this->createMock(Field::class);
$field2 = $this->createMock(Field::class);
$field1->method('__toString')->willReturn("In this week's news");
$field2->method('__toString')->willReturn('Bolt 4 is pretty awesome.');
$this->content->method('getField')
->withConsecutive(['subheading'], ['body'])
->willReturnOnConsecutiveCalls($field1, $field2);
->willReturnCallback(function ($param) use($field1, $field2) {
if ($param === 'subheading') {
return $field1;
}
if ($param === 'body') {
return $field2;
}
return null;
});
$this->definition->method('has')
->withConsecutive(['excerpt_format'], ['subheading'], ['body'])
->willReturn(true);
->willReturnCallback(fn ($param) => $param === 'excerpt_format' || $param === 'subheading' || $param === 'body');
$this->content->method('getId')
->willReturn(1);

$this->assertSame("In this week's news: Bolt 4 is pretty awesome", $this->extension->getExcerpt($this->content));
$this->assertSame("In this week's news: Bolt 4 is pretty awesome",
$this->extension->getExcerpt($this->content));
}

public function testExcerptNoFormat(): void
Expand All @@ -198,7 +223,8 @@ public function testExcerptNoFormat(): void
$this->content->method('getFields')
->willReturn(new ArrayCollection([$title, $subheading, $body]));

$this->assertSame('This subheading is OK. Here is the long body. It is OK too', $this->extension->getExcerpt($this->content));
$this->assertSame('This subheading is OK. Here is the long body. It is OK too',
$this->extension->getExcerpt($this->content));
$this->assertSame('This subheading is OK. Here…', $this->extension->getExcerpt($this->content, 28));
}

Expand Down
6 changes: 2 additions & 4 deletions tests/php/Twig/FieldExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ protected function setUp(): void
public function testFieldLabel(): void
{
$this->fieldType->method('get')
->withConsecutive(['label'])
->wilLReturn('Test field');
->willReturnCallback(fn ($param) => $param === 'label' ? 'Test field' : null);

$this->assertSame('Test field', $this->extension->getLabel($this->field));
}

public function testFieldType(): void
{
$this->fieldType->method('get')
->withConsecutive(['type'])
->willReturn('embed');
->willReturnCallback(fn ($param) => $param === 'type' ? 'embed' : null);

$this->assertSame('embed', $this->extension->getType($this->field));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Twig/SetcontentTokenParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testParse(): void
]);

$compiler = $this->getMockBuilder(Compiler::class)
->setMethods(['raw', 'subcompile', 'write'])
->onlyMethods(['raw', 'subcompile', 'write'])
->setConstructorArgs([$env])
->getMock();

Expand Down
10 changes: 5 additions & 5 deletions tests/php/Widget/Injector/HtmlInjector2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
class HtmlInjector2Test extends StringTestCase
{
public const HTML = '<html><body class="something"
>foo<p><p
>foo<p><p
class="inner">bar</p></p><script></script><script
/></body></html>';

public function providerInjectBeforeTagStart()
public static function providerInjectBeforeTagStart(): array
{
return [
[
Expand All @@ -36,7 +36,7 @@ public function providerInjectBeforeTagStart()
];
}

public function providerInjectBeforeTagEnd()
public static function providerInjectBeforeTagEnd(): array
{
return [
[
Expand All @@ -58,7 +58,7 @@ public function providerInjectBeforeTagEnd()
];
}

public function providerInjectAfterTagStart()
public static function providerInjectAfterTagStart():array
{
return [
[
Expand All @@ -80,7 +80,7 @@ public function providerInjectAfterTagStart()
];
}

public function providerInjectAfterTagEnd()
public static function providerInjectAfterTagEnd():array
{
return [
[
Expand Down
Loading