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

Cleanup tests #523

Merged
merged 4 commits into from
Mar 3, 2020
Merged
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
2 changes: 1 addition & 1 deletion Tests/Functional/TranslationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testTranschoiceWhenTranslationNotYetExtracted()
$client->request('GET', '/apples/view');
$response = $client->getResponse();

$this->assertEquals(200, $response->getStatusCode(), substr($response, 0, 2000));
$this->assertEquals(200, $response->getStatusCode(), $response->getContent());
$this->assertEquals("There are 5 apples\n\nThere are 5 apples", $response->getContent());
}
}
2 changes: 1 addition & 1 deletion Tests/Model/FileSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function getEqualityTests()
$source
->expects($this->once())
->method('equals')
->will($this->returnValue(false))
->willReturn(false)
;
$tests[] = array(
new FileSource('foo'),
Expand Down
8 changes: 4 additions & 4 deletions Tests/Model/MessageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ public function testSet()
public function testSetDoesNotMerge()
{
$m2 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m2->expects($this->any())
$m2
->method('getId')
->will($this->returnValue('foo'));
->willReturn('foo');

$m1 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m1->expects($this->never())
->method('merge');
$m1->expects($this->any())
$m1
->method('getId')
->will($this->returnValue('foo'));
->willReturn('foo');

$col = new MessageCollection();
$col->set($m1);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Model/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function hasSource()
->expects($this->once())
->method('equals')
->with($s2)
->will($this->returnValue(true))
->willReturn(true)
;

$message->addSource($s1);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Translation/Dumper/ArrayStructureDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testPathWithSubPath()
'bar.baz' => new Message('foo.bar.baz'),
),
))
->will($this->returnValue('foo'))
->willReturn('foo')
;

$this->assertEquals('foo', $dumper->dump($catalogue, 'messages'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ final protected function extract($file, FileVisitorInterface $extractor = null)
if (!is_file($file = __DIR__.'/Fixture/'.$file)) {
throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
}
$file = new \SplFileInfo($file);

if (null === $extractor) {
$extractor = $this->getDefaultExtractor();
Expand All @@ -51,7 +50,7 @@ final protected function extract($file, FileVisitorInterface $extractor = null)
$ast = $parser->parse(file_get_contents($file));

$catalogue = new MessageCatalogue();
$extractor->visitPhpFile($file, $catalogue, $ast);
$extractor->visitPhpFile(new \SplFileInfo($file), $catalogue, $ast);

return $catalogue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MyFormType extends AbstractType
class MyFormTypeWithDefaultDomain extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class MyFormType extends AbstractType
class MyFormTypeWithDefaultDomainSetDefault extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private function extract($file, TranslationContainerExtractor $extractor = null)
if (!is_file($file = __DIR__.'/Fixture/'.$file)) {
throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
}
$file = new \SplFileInfo($file);

if (null === $extractor) {
$extractor = new TranslationContainerExtractor();
Expand All @@ -68,7 +67,7 @@ private function extract($file, TranslationContainerExtractor $extractor = null)
$ast = $parser->parse(file_get_contents($file));

$catalogue = new MessageCatalogue();
$extractor->visitPhpFile($file, $catalogue, $ast);
$extractor->visitPhpFile(new \SplFileInfo($file), $catalogue, $ast);

return $catalogue;
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/Translation/Extractor/File/TwigFileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Component\Translation\MessageSelector;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\Source;
Expand Down Expand Up @@ -146,7 +145,7 @@ private function extract($file, TwigFileExtractor $extractor = null)
}

$env = new Environment(new ArrayLoader(array()));
$env->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector())));
$env->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator()));
$env->addExtension(new TranslationExtension($translator, true));
$env->addExtension(new RoutingExtension(new UrlGenerator(new RouteCollection(), new RequestContext())));
$env->addExtension(new FormExtension());
Expand Down
3 changes: 1 addition & 2 deletions Tests/Translation/Extractor/File/ValidationExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ private function extract($file, ValidationExtractor $extractor = null)
if (!is_file($file = __DIR__.'/Fixture/'.$file)) {
throw new RuntimeException(sprintf('The file "%s" does not exist.', $file));
}
$file = new \SplFileInfo($file);

$metadataFactoryClass = LazyLoadingMetadataFactory::class;

Expand All @@ -72,7 +71,7 @@ private function extract($file, ValidationExtractor $extractor = null)
$ast = $parser->parse(file_get_contents($file));

$catalogue = new MessageCatalogue();
$extractor->visitPhpFile($file, $catalogue, $ast);
$extractor->visitPhpFile(new \SplFileInfo($file), $catalogue, $ast);

return $catalogue;
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/Translation/Extractor/FileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\File\TranslationContainerExtractor;
use JMS\TranslationBundle\Translation\Extractor\File\DefaultPhpFileExtractor;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
use Symfony\Bridge\Twig\Extension\TranslationExtension as SymfonyTranslationExtension;
Expand Down Expand Up @@ -101,7 +100,7 @@ public function testExtractWithSimpleTestFixtures()
private function extract($directory)
{
$twig = new Environment(new ArrayLoader(array()));
$twig->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector())));
$twig->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator()));
$twig->addExtension(new TranslationExtension($translator));
$loader=new FilesystemLoader(realpath(__DIR__."/Fixture/SimpleTest/Resources/views/"));
$twig->setLoader($loader);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Translation/ExtractorManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testOnlySomeExtractorsEnabled()
$bar
->expects($this->once())
->method('extract')
->will($this->returnValue($catalogue))
->willReturn($catalogue)
;

$manager = $this->getManager(null, array(
Expand Down
4 changes: 2 additions & 2 deletions Tests/Translation/FileWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function testCatalogueIsSortedBeforeBeingDumped()
$dumper
->expects($this->once())
->method('dump')
->will($this->returnCallback(function ($v) use ($self) {
->willReturnCallback(function ($v) use ($self) {
$self->assertEquals(array('foo.bar', 'foo.bar.baz'), array_keys($v->getDomain('messages')->all()));
}))
})
;

$writer = new FileWriter(array(
Expand Down
2 changes: 1 addition & 1 deletion Tests/Translation/Loader/SymfonyLoaderAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testLoad()
$symfonyLoader->expects($this->once())
->method('load')
->with('foo', 'en', 'messages')
->will($this->returnValue($symfonyCatalogue));
->willReturn($symfonyCatalogue);

$adapter = new SymfonyLoaderAdapter($symfonyLoader);
$bundleCatalogue = $adapter->load('foo', 'en', 'messages');
Expand Down
3 changes: 1 addition & 2 deletions Tests/Twig/BaseTwigTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace JMS\TranslationBundle\Tests\Twig;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Bridge\Twig\Extension\TranslationExtension as SymfonyTranslationExtension;
use JMS\TranslationBundle\Twig\TranslationExtension;
Expand All @@ -34,7 +33,7 @@ final protected function parse($file, $debug = false)
$content = file_get_contents(__DIR__.'/Fixture/'.$file);

$env = new Environment(new ArrayLoader(array()));
$env->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector())));
$env->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator()));
$env->addExtension(new TranslationExtension($translator, $debug));

return $env->compile($env->parse($env->tokenize(new Source($content, 'whatever')))->getNode('body'));
Expand Down