From a45b93d42368272e59bcf696f9ccab00d1936018 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 23 Mar 2016 20:28:12 +0100 Subject: [PATCH] [2.7] fix mocking of some methods --- .../Component/HttpKernel/Tests/KernelTest.php | 2 +- .../Tests/Writer/TranslationWriterTest.php | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index bd1b428d09..7b1cdcd50d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -99,7 +99,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase public function testClassCacheIsNotLoadedByDefault() { - $kernel = $this->getKernel(array('initializeBundles', 'initializeContainer')); + $kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache')); $kernel->expects($this->never()) ->method('doLoadClassCache'); diff --git a/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php b/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php index 501ced82e3..f7a8a83d24 100644 --- a/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php +++ b/src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Translation\Tests\Writer; +use Symfony\Component\Translation\Dumper\DumperInterface; use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\Writer\TranslationWriter; @@ -30,18 +31,35 @@ class TranslationWriterTest extends \PHPUnit_Framework_TestCase public function testDisableBackup() { - $dumper = $this->getMock('Symfony\Component\Translation\Dumper\DumperInterface'); - $dumper - ->expects($this->never()) - ->method('setBackup'); - $phpDumper = $this->getMock('Symfony\Component\Translation\Dumper\PhpFileDumper'); - $phpDumper - ->expects($this->once()) - ->method('setBackup'); + $nonBackupDumper = new NonBackupDumper(); + $backupDumper = new BackupDumper(); $writer = new TranslationWriter(); - $writer->addDumper('test', $dumper); - $writer->addDumper('php', $phpDumper); + $writer->addDumper('non_backup', $nonBackupDumper); + $writer->addDumper('backup', $backupDumper); $writer->disableBackup(); + + $this->assertFalse($backupDumper->backup, 'backup can be disabled if setBackup() method does exist'); + } +} + +class NonBackupDumper implements DumperInterface +{ + public function dump(MessageCatalogue $messages, $options = array()) + { + } +} + +class BackupDumper implements DumperInterface +{ + public $backup = true; + + public function dump(MessageCatalogue $messages, $options = array()) + { + } + + public function setBackup($backup) + { + $this->backup = $backup; } }