Skip to content

Commit

Permalink
Some tests improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista committed Oct 12, 2018
1 parent 4d0d3b1 commit 7177163
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
language: php

cache:
directories:
- $HOME/.composer/cache/files

git:
depth: 3

matrix:
fast_finish: true
include:
Expand Down
83 changes: 36 additions & 47 deletions tests/Functional/Command/LoadFixturesCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,99 +1,88 @@
<?php

declare(strict_types=1);
<?php declare(strict_types=1);

namespace Facile\MongoDbBundle\Tests\Functional\Command;

use Facile\MongoDbBundle\Command\LoadFixturesCommand;
use Facile\MongoDbBundle\Tests\Functional\AppTestCase;
use MongoDB\Collection;
use MongoDB\Database;
use Symfony\Component\Console\Tester\CommandTester;

class LoadFixturesAppTest extends AppTestCase
class LoadFixturesCommandTest extends AppTestCase
{
public function test_command()
/** @var Database $conn */
private $conn;

protected function setUp()
{
/** @var Database $conn */
$conn = $this->getContainer()->get('mongo.connection');
self::assertEquals('testFunctionaldb', $conn->getDatabaseName());
parent::setUp();

$conn->createCollection('testFixturesCollection');
$this->conn = $this->getContainer()->get('mongo.connection');
self::assertEquals('testFunctionaldb', $this->conn->getDatabaseName());
}

$this->getApplication()->add(new LoadFixturesCommand());
protected function tearDown()
{
parent::tearDown();

$command = $this->getApplication()->find('mongodb:fixtures:load');
$this->conn->dropCollection('testFixturesCollection');
$this->conn->dropCollection('testFixturesOrderedCollection');
}

public function test_command()
{
$this->conn->createCollection('testFixturesCollection');

$this->getApplication()->add(new LoadFixturesCommand());
$command = $this->getApplication()->find('mongodb:fixtures:load');
$commandTester = new CommandTester($command);
$commandTester->execute(
[
'command' => $command->getName(),
'addFixturesPath' => __DIR__ . "/../../fixtures/DataFixtures"
'addFixturesPath' => __DIR__ . '/../../fixtures/DataFixtures'
]
);

/** @var Collection $collection */
$collection = $conn->selectCollection('testFixturesCollection');
$collection = $this->conn->selectCollection('testFixturesCollection');

$fixtures = $collection->find(['type' => 'fixture']);
$fixtures = $fixtures->toArray();
$fixtures = $collection->find(['type' => 'fixture'])
->toArray();

self::assertEquals('fixture', $fixtures[0]['type']);
self::assertEquals('test', $fixtures[0]['data']);

self::assertContains("Done, loaded 4 fixtures files", $commandTester->getDisplay());

$conn->dropCollection('testFixturesCollection');
self::assertContains('Done, loaded 4 fixtures files', $commandTester->getDisplay());
}

public function test_command_not_fixtures_found()
{
/** @var Database $conn */
$conn = $this->getContainer()->get('mongo.connection');
self::assertEquals('testFunctionaldb', $conn->getDatabaseName());

$this->getApplication()->add(new LoadFixturesCommand());

$command = $this->getApplication()->find('mongodb:fixtures:load');

$commandTester = new CommandTester($command);

self::expectException(\InvalidArgumentException::class);
$this->expectException(\InvalidArgumentException::class);
$commandTester->execute([]);

$conn->dropCollection('testFixturesCollection');
}

public function test_command_order_fixtures()
{

/** @var Database $conn */
$conn = $this->getContainer()->get('mongo.connection');

$conn->dropCollection('testFixturesOrderedCollection');

self::assertEquals('testFunctionaldb', $conn->getDatabaseName());

$conn->createCollection('testFixturesOrderedCollection');
$this->conn->createCollection('testFixturesOrderedCollection');

$this->getApplication()->add(new LoadFixturesCommand());

$command = $this->getApplication()->find('mongodb:fixtures:load');

$commandTester = new CommandTester($command);
$commandTester->execute(
[
'command' => $command->getName(),
'addFixturesPath' => __DIR__ . "/../../fixtures/DataFixtures"
'addFixturesPath' => __DIR__ . '/../../fixtures/DataFixtures'
]
);

/** @var Collection $collection */
$collection = $conn->selectCollection('testFixturesOrderedCollection');
$fixtures = $collection->find(['type' => 'fixture']);
$fixtures = $fixtures->toArray();
$collection = $this->conn->selectCollection('testFixturesOrderedCollection');
$fixtures = $collection
->find(['type' => 'fixture'])
->toArray();

self::assertEquals(3, count($fixtures));
$this->assertCount(3, $fixtures);

$fixture = current($fixtures);

Expand All @@ -113,7 +102,7 @@ public function test_command_order_fixtures()
self::assertEquals('Alice in Wonderland - 2010', $fixture['data']);
self::assertEquals(2, $fixture['expectedPosition']);

$conn->dropCollection('testFixturesOrderedCollection');
$this->conn->dropCollection('testFixturesOrderedCollection');
}

}

0 comments on commit 7177163

Please sign in to comment.