Refactor functional to unit test.

Remove a functional which is already backed by unit test
This commit is contained in:
Benoît Burnichon
2016-02-06 00:36:15 +01:00
parent 181acbe720
commit e40a092156
2 changed files with 61 additions and 152 deletions

View File

@@ -2,141 +2,99 @@
namespace Alchemy\Tests\Phrasea\Border\Checker; namespace Alchemy\Tests\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\Checker\AbstractChecker; use Alchemy\Phrasea\Border\Checker\AbstractChecker;
use Alchemy\Phrasea\Border\File; use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Translation\TranslatorInterface;
/** class AbstractCheckerTest extends \PHPUnit_Framework_TestCase
* @group functional
* @group legacy
*/
class AbstractCheckerTest extends \PhraseanetTestCase
{ {
/**
* @var Application
*/
private $app;
/** /**
* @var AbstractChecker * @var AbstractChecker
*/ */
protected $object; private $sut;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->object = $this->getMockBuilder(AbstractChecker::class) $this->app = $this->prophesize(Application::class);
->setConstructorArgs([self::$DI['app']])
->getMockForAbstractClass(); $this->sut = $this->getMockBuilder(AbstractChecker::class)
$this->file = $this->getMock('\\Alchemy\\Phrasea\\Border\\File', ['getCollection'], [], 'CheckerTesterMock' . mt_rand(), false); ->setConstructorArgs([$this->app->reveal()])
} ->getMockForAbstractClass();
public function tearDown()
{
$this->file = null;
parent::tearDown();
} }
/** /**
* @covers Alchemy\Phrasea\Border\Checker\AbstractChecker::restrictToDataboxes * @dataProvider getDataboxesCombination
* @covers Alchemy\Phrasea\Border\Checker\AbstractChecker::isApplicable
* @dataProvider getDataboxesCombinaison
*/ */
public function testRestrictToDataboxes($databoxes, $collection, $assertion) public function testRestrictToDataboxes($databoxes, $collection, $assertion)
{ {
$this->file->expects($this->any()) $file = $this->prophesize(File::class);
->method('getCollection') $file->getCollection()->willReturn($collection);
->will($this->returnValue($collection));
$this->object->restrictToDataboxes($databoxes); $this->sut->restrictToDataboxes($databoxes);
$this->assertEquals($assertion, $this->object->isApplicable($this->file)); $this->assertEquals($assertion, $this->sut->isApplicable($file->reveal()));
} }
public function getDataboxesCombinaison() public function getDataboxesCombination()
{ {
$databox = $collection = null; $databox = $this->prophesize(\databox::class);
$app = $this->loadApp(); $databox->get_sbas_id()->willReturn(1);
foreach ($app->getDataboxes() as $db) { $collection = $this->prophesize(\collection::class);
if (! $collection) { $collection->get_databox()->willReturn($databox->reveal());
foreach ($db->get_collections() as $coll) { $collection->get_base_id()->willReturn(2);
$collection = $coll;
break;
}
}
if (! $collection) {
$this->fail('Unable to get a collection');
}
if ($db->get_sbas_id() != $collection->get_databox()->get_sbas_id()) { $anotherDatabox = $this->prophesize(\databox::class);
$databox = $db; $anotherDatabox->get_sbas_id()->willReturn(3);
break;
}
}
$ret = [ return [
[[$collection->get_databox()], $collection, true], [[], $collection, true],
[$collection->get_databox(), $collection, true], [[$databox->reveal()], $collection, true],
[$collection->get_databox(), null, true], [$databox->reveal(), $collection, true],
[$databox->reveal(), null, true],
[$anotherDatabox->reveal(), $collection, false],
]; ];
if ($databox) {
$ret[] = [$databox, $collection, false];
}
return $ret;
} }
/** /**
* @covers Alchemy\Phrasea\Border\Checker\AbstractChecker::restrictToCollections * @dataProvider getCollectionsCombination
* @covers Alchemy\Phrasea\Border\Checker\AbstractChecker::isApplicable
* @dataProvider getCollectionsCombinaison
*/ */
public function testRestrictToCollections($collection, $othercollection, $assertion) public function testRestrictToCollections($collection, $othercollection, $assertion)
{ {
$this->file->expects($this->any()) $file = $this->prophesize(File::class);
->method('getCollection') $file->getCollection()->willReturn($othercollection);
->will($this->returnValue($othercollection));
$this->object->restrictToCollections($collection); $this->sut->restrictToCollections($collection);
$this->assertEquals($assertion, $this->object->isApplicable($this->file)); $this->assertEquals($assertion, $this->sut->isApplicable($file->reveal()));
} }
public function getCollectionsCombinaison() public function getCollectionsCombination()
{ {
$othercollection = $collection = null; $databox = $this->prophesize(\databox::class);
$app = $this->loadApp(); $databox->get_sbas_id()->willReturn(1);
$databoxes = $app->getDataboxes();
if (count($databoxes) === 0) {
$this->fail('Unable to find collections');
}
$databox = array_pop($databoxes);
foreach ($databoxes as $db) { $collectionProphecy = $this->prophesize(\collection::class);
if (! $collection) { $collectionProphecy->get_databox()->willReturn($databox->reveal());
foreach ($db->get_collections() as $coll) { $collectionProphecy->get_base_id()->willReturn(2);
$collection = $coll; $collection = $collectionProphecy->reveal();
break;
}
}
if (! $othercollection && $collection) { $otherCollectionProphecy = $this->prophesize(\collection::class);
foreach ($db->get_collections() as $coll) { $otherCollectionProphecy->get_databox()->willReturn($databox->reveal());
if ($coll->get_base_id() != $collection->get_base_id()) { $otherCollectionProphecy->get_base_id()->willReturn(3);
$othercollection = $coll; $othercollection = $otherCollectionProphecy->reveal();
break;
}
}
}
}
if (null === $othercollection) {
$othercollection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'other coll');
}
if (null === $collection) {
$collection = \collection::create($app, $databox, $app['phraseanet.appbox'], 'other coll');
}
return [ return [
[[], $collection, true],
[[$collection], $collection, true], [[$collection], $collection, true],
[$collection, $collection, true], [$collection, $collection, true],
[$collection, null, true], [$collection, null, true],
@@ -151,8 +109,8 @@ class AbstractCheckerTest extends \PhraseanetTestCase
*/ */
public function testMixCollectionFirst($databox, $collection) public function testMixCollectionFirst($databox, $collection)
{ {
$this->object->restrictToCollections($collection); $this->sut->restrictToCollections($collection);
$this->object->restrictToDataboxes($databox); $this->sut->restrictToDataboxes($databox);
} }
/** /**
@@ -161,8 +119,8 @@ class AbstractCheckerTest extends \PhraseanetTestCase
*/ */
public function testMixDataboxFirst($databox, $collection) public function testMixDataboxFirst($databox, $collection)
{ {
$this->object->restrictToDataboxes($databox); $this->sut->restrictToDataboxes($databox);
$this->object->restrictToCollections($collection); $this->sut->restrictToCollections($collection);
} }
/** /**
@@ -171,7 +129,7 @@ class AbstractCheckerTest extends \PhraseanetTestCase
*/ */
public function testInvalidDatabox($databox, $collection) public function testInvalidDatabox($databox, $collection)
{ {
$this->object->restrictToDataboxes($collection); $this->sut->restrictToDataboxes($collection);
} }
/** /**
@@ -180,25 +138,17 @@ class AbstractCheckerTest extends \PhraseanetTestCase
*/ */
public function testInvalidCollection($databox, $collection) public function testInvalidCollection($databox, $collection)
{ {
$this->object->restrictToCollections($databox); $this->sut->restrictToCollections($databox);
} }
public function getDataboxAndCollection() public function getDataboxAndCollection()
{ {
$databox = $collection = null; $databox = $this->prophesize(\databox::class);
$app = $this->loadApp(); $databox->get_sbas_id()->willReturn(1);
foreach ($app->getDataboxes() as $db) { $collection = $this->prophesize(\collection::class);
if (! $databox) { $collection->get_databox()->willReturn($databox->reveal());
$databox = $db; $collection->get_base_id()->willReturn(2);
}
if (! $collection) {
foreach ($db->get_collections() as $coll) {
$collection = $coll;
break;
}
}
}
return [ return [
[$databox, $collection], [$databox, $collection],

View File

@@ -550,47 +550,6 @@ class ManagerTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals(['Phraseanet:tf-duration'], $toFound); $this->assertEquals(['Phraseanet:tf-duration'], $toFound);
} }
/**
* @covers Alchemy\Phrasea\Border\Manager::getVisa
*/
public function testGetVisa()
{
$records = [];
$postProcessRecord = function ($record) use (&$records) {
$records[] = $record;
};
self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
$visa = $this->object->getVisa(File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']));
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Visa', $visa);
$this->assertTrue($visa->isValid());
$this->object->process($this->session, File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']), $postProcessRecord);
$visa = $this->object->getVisa(File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']));
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Visa', $visa);
$this->assertTrue($visa->isValid());
$this->object->registerChecker(new Sha256(self::$DI['app']));
$visa = $this->object->getVisa(File::buildFromPathfile(self::$file1, self::$DI['collection'], self::$DI['app']));
$this->assertInstanceOf('\\Alchemy\\Phrasea\\Border\\Visa', $visa);
$this->assertFalse($visa->isValid());
foreach ($records as $record) {
if ($record instanceof \record_adapter) {
$record->delete();
}
}
}
/** /**
* @covers Alchemy\Phrasea\Border\Manager::registerChecker * @covers Alchemy\Phrasea\Border\Manager::registerChecker
* @covers Alchemy\Phrasea\Border\Manager::getCheckers * @covers Alchemy\Phrasea\Border\Manager::getCheckers