Skip to content

Commit f27c499

Browse files
committed
minor #360 Fix tests for php7 (dbrumann)
This PR was merged into the 3.x-dev branch. Discussion ---------- Fix tests for php7 Combines previous PRs #358 and #359 together with fixes for failing tests on Travis. * Updates travis test matrix: * Adds PHP 7.4 to test matrix * Expands test matrix for PHP 7.2+ to check against both monolog 1 & 2 * Fixes PHPUnit deprecations: * Fixes invalid method signature for `setUp()` * Replaces deprecated assertions (assertContains, assertNotContains) * Replaces deprecated expectedExceptions annotations * Fixes missing service definitions in container configurations Closes #351 as well Commits ------- e71163a Fix tests failing in PHP 7.1+
2 parents 72e798c + e71163a commit f27c499

9 files changed

+98
-58
lines changed

.travis.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,32 @@ matrix:
2424
- php: 7.1
2525
# There is a bug in PHPUnit 5.7
2626
env: SYMFONY_PHPUNIT_VERSION=6.5
27+
# Test against seldaek/monolog 1.x
2728
- php: 7.2
29+
env: MONOLOG_VERSION=1.*
2830
- php: 7.3
31+
env: MONOLOG_VERSION=1.*
32+
- php: 7.4
33+
env: MONOLOG_VERSION=1.*
34+
# Test against seldaek/monolog 2.x
35+
- php: 7.2
36+
env: MONOLOG_VERSION=2.*
37+
- php: 7.3
38+
env: MONOLOG_VERSION=2.*
39+
- php: 7.4
40+
env: MONOLOG_VERSION=2.*
2941
# Test against dev versions
3042
- php: nightly
31-
env: DEPENDENCIES=dev
43+
env: DEPENDENCIES=dev MONOLOG_VERSION=1.*
44+
- php: nightly
45+
env: DEPENDENCIES=dev MONOLOG_VERSION=2.*
3246
allow_failures:
33-
- env: DEPENDENCIES=dev
47+
- php: nightly
3448

3549
before_install:
3650
- composer self-update
3751
- if [ "$DEPENDENCIES" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
52+
- if [ "$MONOLOG_VERSION" != "" ]; then composer require --dev --no-update monolog/monolog:"$MONOLOG_VERSION"; fi;
3853
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony:"$SYMFONY_VERSION"; fi
3954

4055
install:

Tests/DependencyInjection/Compiler/AddSwiftMailerTransportPassTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class AddSwiftMailerTransportPassTest extends TestCase
2626

2727
private $definition;
2828

29-
protected function setUp()
29+
/**
30+
* @before
31+
*/
32+
protected function doSetUp()
3033
{
3134
$this->compilerPass = new AddSwiftMailerTransportPass();
3235
$this->definition = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Definition')->getMock();

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Monolog\Logger;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Bundle\MonologBundle\DependencyInjection\Configuration;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\Definition\Processor;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920

@@ -143,9 +144,6 @@ public function testArrays()
143144
$this->assertEquals('D', $config['handlers']['bar']['channels']['elements'][1]);
144145
}
145146

146-
/**
147-
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
148-
*/
149147
public function testInvalidArrays()
150148
{
151149
$configs = [
@@ -160,12 +158,11 @@ public function testInvalidArrays()
160158
]
161159
];
162160

161+
$this->expectException(InvalidConfigurationException::class);
162+
163163
$config = $this->process($configs);
164164
}
165165

166-
/**
167-
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
168-
*/
169166
public function testMergingInvalidChannels()
170167
{
171168
$configs = [
@@ -187,6 +184,8 @@ public function testMergingInvalidChannels()
187184
]
188185
];
189186

187+
$this->expectException(InvalidConfigurationException::class);
188+
190189
$config = $this->process($configs);
191190
}
192191

Tests/DependencyInjection/FixtureMonologExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testPsr3MessageProcessingEnabled()
202202

203203
$methodCalls = $logger->getMethodCalls();
204204

205-
$this->assertContains(['pushProcessor', [new Reference('monolog.processor.psr_log_message')]], $methodCalls, 'The PSR-3 processor should be enabled', false, false);
205+
$this->assertContainsEquals(['pushProcessor', [new Reference('monolog.processor.psr_log_message')]], $methodCalls, 'The PSR-3 processor should be enabled');
206206
}
207207

208208
public function testPsr3MessageProcessingDisabled()
@@ -213,7 +213,7 @@ public function testPsr3MessageProcessingDisabled()
213213

214214
$methodCalls = $logger->getMethodCalls();
215215

216-
$this->assertNotContains(['pushProcessor', [new Reference('monolog.processor.psr_log_message')]], $methodCalls, 'The PSR-3 processor should not be enabled', false, false);
216+
$this->assertNotContainsEquals(['pushProcessor', [new Reference('monolog.processor.psr_log_message')]], $methodCalls, 'The PSR-3 processor should not be enabled');
217217
}
218218

219219
public function testNativeMailer()

Tests/DependencyInjection/Fixtures/yml/multiple_handlers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ monolog:
55
path: /tmp/symfony.log
66
bubble: false
77
level: ERROR
8-
file_permission: 0666
8+
file_permission: 438 # decimal representation of 0666 octal
99
main:
1010
type: fingers_crossed
1111
action_level: ERROR

0 commit comments

Comments
 (0)