Skip to content

Commit

Permalink
Fix deprecation on 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Aug 7, 2019
1 parent 3cd7726 commit 4d6765b
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -30,6 +30,9 @@ matrix:
env: deps=high
- php: 7.3
env: deps=low
- php: 7.4snapshot
allow_failures:
- php: 7.4snapshot
fast_finish: true

cache:
Expand Down
Expand Up @@ -120,7 +120,7 @@ public function testGetMetadata()
CacheItem::METADATA_EXPIRY => 9.5 + time(),
CacheItem::METADATA_CTIME => 1000,
];
$this->assertEquals($expected, $item->getMetadata(), 'Item metadata should embed expiry and ctime.', .6);
$this->assertEqualsWithDelta($expected, $item->getMetadata(), .6, 'Item metadata should embed expiry and ctime.');
}

public function testDefaultLifeTime()
Expand Down
Expand Up @@ -14,26 +14,25 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;

class NodeDefinitionTest extends TestCase
{
public function testDefaultPathSeparatorIsDot()
{
$node = $this->getMockForAbstractClass(NodeDefinition::class, ['foo']);

$this->assertAttributeSame('.', 'pathSeparator', $node);
}

public function testSetPathSeparatorChangesChildren()
{
$node = new ArrayNodeDefinition('foo');
$scalar = new ScalarNodeDefinition('bar');
$node->append($scalar);

$node->setPathSeparator('/');

$this->assertAttributeSame('/', 'pathSeparator', $node);
$this->assertAttributeSame('/', 'pathSeparator', $scalar);
$parentNode = new ArrayNodeDefinition('name');
$childNode = $this->createMock(NodeDefinition::class);

$childNode
->expects($this->once())
->method('setPathSeparator')
->with('/');
$childNode
->expects($this->once())
->method('setParent')
->with($parentNode)
->willReturn($childNode);
$parentNode->append($childNode);

$parentNode->setPathSeparator('/');
}
}
Expand Up @@ -142,6 +142,10 @@ public function testRegisterClassesWithExclude()

public function testRegisterClassesWithExcludeAsArray()
{
if (\PHP_VERSION_ID >= 70400) {
throw new Warning('PHP 7.4 breaks this test, see https://bugs.php.net/78351.');
}

$container = new ContainerBuilder();
$container->setParameter('sub_dir', 'Sub');
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
Expand Down
Expand Up @@ -51,11 +51,11 @@ public function testChoiceTranslationLocaleOption()
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContains(new ChoiceView('DE', 'DE', 'Німеччина'), $choices, '', false, false);
$this->assertContains(new ChoiceView('GB', 'GB', 'Велика Британія'), $choices, '', false, false);
$this->assertContains(new ChoiceView('US', 'US', 'Сполучені Штати'), $choices, '', false, false);
$this->assertContains(new ChoiceView('FR', 'FR', 'Франція'), $choices, '', false, false);
$this->assertContains(new ChoiceView('MY', 'MY', 'Малайзія'), $choices, '', false, false);
$this->assertContainsEquals(new ChoiceView('DE', 'DE', 'Німеччина'), $choices);
$this->assertContainsEquals(new ChoiceView('GB', 'GB', 'Велика Британія'), $choices);
$this->assertContainsEquals(new ChoiceView('US', 'US', 'Сполучені Штати'), $choices);
$this->assertContainsEquals(new ChoiceView('FR', 'FR', 'Франція'), $choices);
$this->assertContainsEquals(new ChoiceView('MY', 'MY', 'Малайзія'), $choices);
}

public function testUnknownCountryIsNotIncluded()
Expand Down
Expand Up @@ -48,9 +48,9 @@ public function testChoiceTranslationLocaleOption()
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContains(new ChoiceView('EUR', 'EUR', 'євро'), $choices, '', false, false);
$this->assertContains(new ChoiceView('USD', 'USD', 'долар США'), $choices, '', false, false);
$this->assertContains(new ChoiceView('SIT', 'SIT', 'словенський толар'), $choices, '', false, false);
$this->assertContainsEquals(new ChoiceView('EUR', 'EUR', 'євро'), $choices);
$this->assertContainsEquals(new ChoiceView('USD', 'USD', 'долар США'), $choices);
$this->assertContainsEquals(new ChoiceView('SIT', 'SIT', 'словенський толар'), $choices);
}

public function testSubmitNull($expected = null, $norm = null, $view = null)
Expand Down
Expand Up @@ -50,10 +50,10 @@ public function testChoiceTranslationLocaleOption()
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices, '', false, false);
$this->assertContains(new ChoiceView('fr', 'fr', 'французька'), $choices, '', false, false);
$this->assertContains(new ChoiceView('my', 'my', 'бірманська'), $choices, '', false, false);
$this->assertContainsEquals(new ChoiceView('en', 'en', 'англійська'), $choices);
$this->assertContainsEquals(new ChoiceView('en_US', 'en_US', 'англійська (США)'), $choices);
$this->assertContainsEquals(new ChoiceView('fr', 'fr', 'французька'), $choices);
$this->assertContainsEquals(new ChoiceView('my', 'my', 'бірманська'), $choices);
}

public function testMultipleLanguagesIsNotIncluded()
Expand Down
Expand Up @@ -48,9 +48,9 @@ public function testChoiceTranslationLocaleOption()
->createView()->vars['choices'];

// Don't check objects for identity
$this->assertContains(new ChoiceView('en', 'en', 'англійська'), $choices, '', false, false);
$this->assertContains(new ChoiceView('en_GB', 'en_GB', 'англійська (Велика Британія)'), $choices, '', false, false);
$this->assertContains(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'китайська (традиційна, Макао, О.А.Р Китаю)'), $choices, '', false, false);
$this->assertContainsEquals(new ChoiceView('en', 'en', 'англійська'), $choices);
$this->assertContainsEquals(new ChoiceView('en_GB', 'en_GB', 'англійська (Велика Британія)'), $choices);
$this->assertContainsEquals(new ChoiceView('zh_Hant_MO', 'zh_Hant_MO', 'китайська (традиційна, Макао, О.А.Р Китаю)'), $choices);
}

public function testSubmitNull($expected = null, $norm = null, $view = null)
Expand Down
Expand Up @@ -31,19 +31,19 @@ public function testThrottling()

$start = time();
$transport->send($message, $envelope);
$this->assertEquals(0, time() - $start, '', 1);
$this->assertEqualsWithDelta(0, time() - $start, 1);
$transport->send($message, $envelope);
$this->assertEquals(5, time() - $start, '', 1);
$this->assertEqualsWithDelta(5, time() - $start, 1);
$transport->send($message, $envelope);
$this->assertEquals(10, time() - $start, '', 1);
$this->assertEqualsWithDelta(10, time() - $start, 1);
$transport->send($message, $envelope);
$this->assertEquals(15, time() - $start, '', 1);
$this->assertEqualsWithDelta(15, time() - $start, 1);

$start = time();
$transport->setMaxPerSecond(-3);
$transport->send($message, $envelope);
$this->assertEquals(0, time() - $start, '', 1);
$this->assertEqualsWithDelta(0, time() - $start, 1);
$transport->send($message, $envelope);
$this->assertEquals(0, time() - $start, '', 1);
$this->assertEqualsWithDelta(0, time() - $start, 1);
}
}
Expand Up @@ -22,7 +22,7 @@ class HandlersLocatorTest extends TestCase
{
public function testItYieldsHandlerDescriptors()
{
$handler = $this->createPartialMock(\stdClass::class, ['__invoke']);
$handler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);
$locator = new HandlersLocator([
DummyMessage::class => [$handler],
]);
Expand All @@ -32,13 +32,13 @@ public function testItYieldsHandlerDescriptors()

public function testItReturnsOnlyHandlersMatchingTransport()
{
$firstHandler = $this->createPartialMock(\stdClass::class, ['__invoke']);
$secondHandler = $this->createPartialMock(\stdClass::class, ['__invoke']);
$firstHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);
$secondHandler = $this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']);

$locator = new HandlersLocator([
DummyMessage::class => [
$first = new HandlerDescriptor($firstHandler, ['alias' => 'one']),
new HandlerDescriptor($this->createPartialMock(\stdClass::class, ['__invoke']), ['from_transport' => 'ignored', 'alias' => 'two']),
new HandlerDescriptor($this->createPartialMock(HandlersLocatorTestCallable::class, ['__invoke']), ['from_transport' => 'ignored', 'alias' => 'two']),
$second = new HandlerDescriptor($secondHandler, ['from_transport' => 'transportName', 'alias' => 'three']),
],
]);
Expand All @@ -51,3 +51,10 @@ public function testItReturnsOnlyHandlersMatchingTransport()
)));
}
}

class HandlersLocatorTestCallable
{
public function __invoke()
{
}
}
Expand Up @@ -42,7 +42,7 @@ public function testExecuteMiddlewareOnActivatedWithCallable()
$message = new DummyMessage('Hello');
$envelope = new Envelope($message);

$activated = $this->createPartialMock(\stdClass::class, ['__invoke']);
$activated = $this->createPartialMock(ActivationMiddlewareTestCallable::class, ['__invoke']);
$activated->expects($this->once())->method('__invoke')->with($envelope)->willReturn(true);

$stack = $this->getStackMock(false);
Expand All @@ -68,3 +68,10 @@ public function testExecuteMiddlewareOnDeactivated()
$decorator->handle($envelope, $this->getStackMock());
}
}

class ActivationMiddlewareTestCallable
{
public function __invoke()
{
}
}
Expand Up @@ -28,7 +28,7 @@ public function testItCallsTheHandlerAndNextMiddleware()
$message = new DummyMessage('Hey');
$envelope = new Envelope($message);

$handler = $this->createPartialMock(\stdClass::class, ['__invoke']);
$handler = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);

$middleware = new HandleMessageMiddleware(new HandlersLocator([
DummyMessage::class => [$handler],
Expand Down Expand Up @@ -62,15 +62,15 @@ public function testItAddsHandledStamps(array $handlers, array $expectedStamps,

public function itAddsHandledStampsProvider()
{
$first = $this->createPartialMock(\stdClass::class, ['__invoke']);
$first = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$first->method('__invoke')->willReturn('first result');
$firstClass = \get_class($first);

$second = $this->createPartialMock(\stdClass::class, ['__invoke']);
$second = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$second->method('__invoke')->willReturn(null);
$secondClass = \get_class($second);

$failing = $this->createPartialMock(\stdClass::class, ['__invoke']);
$failing = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$failing->method('__invoke')->will($this->throwException(new \Exception('handler failed.')));

yield 'A stamp is added' => [
Expand Down Expand Up @@ -129,3 +129,10 @@ public function testAllowNoHandlers()
$this->assertInstanceOf(Envelope::class, $middleware->handle(new Envelope(new DummyMessage('Hey')), new StackMiddleware()));
}
}

class HandleMessageMiddlewareTestCallable
{
public function __invoke()
{
}
}
Expand Up @@ -28,7 +28,7 @@ public function testSend()
$encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]];

$connection = $this->createMock(Connection::class);
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'])->willReturn(15);
$connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers'])->willReturn('15');

$serializer = $this->createMock(SerializerInterface::class);
$serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded);
Expand Down
Expand Up @@ -58,7 +58,7 @@ public function send(Envelope $envelope): Envelope
{
/** @var SentStamp|null $sentStamp */
$sentStamp = $envelope->last(SentStamp::class);
$alias = null === $sentStamp ? 'sync' : $sentStamp->getSenderAlias() ?: $sentStamp->getSenderClass();
$alias = null === $sentStamp ? 'sync' : ($sentStamp->getSenderAlias() ?: $sentStamp->getSenderClass());

$envelope = $envelope->with(new ReceivedStamp($alias));

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Stopwatch/Tests/StopwatchTest.php
Expand Up @@ -87,7 +87,7 @@ public function testStop()
$event = $stopwatch->stop('foo');

$this->assertInstanceOf('Symfony\Component\Stopwatch\StopwatchEvent', $event);
$this->assertEquals(200, $event->getDuration(), '', self::DELTA);
$this->assertEqualsWithDelta(200, $event->getDuration(), self::DELTA);
}

public function testUnknownEvent()
Expand Down

0 comments on commit 4d6765b

Please sign in to comment.