Skip to content

Commit

Permalink
Updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinogradsoft committed Oct 6, 2021
1 parent 3ce953c commit 5839aba
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 56 deletions.
43 changes: 7 additions & 36 deletions tests/Unit/ArrayDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,9 @@
class ArrayDriverTest extends TestCase
{

public function testConstruct()
{
$arrayDriver = new ArrayDriver($nodeFactory = new DummyNodeFactory());
$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('nodeFactory');
$property->setAccessible(true);
$objectValue = $property->getValue($arrayDriver);
self::assertSame($objectValue, $nodeFactory);
}

public function testGetNodeFactory()
{
$arrayDriver = new ArrayDriver($nodeFactory = new DummyNodeFactory());
$factory = $arrayDriver->getNodeFactory();
self::assertSame($factory, $nodeFactory);
}

public function testIsLeaf()
{
$arrayDriver = new ArrayDriver(new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
self::assertTrue($arrayDriver->isLeaf([5]));
self::assertTrue($arrayDriver->isLeaf(['string']));
self::assertFalse($arrayDriver->isLeaf([
Expand All @@ -38,7 +21,7 @@ public function testIsLeaf()

public function testIsLeafWithSnap()
{
$arrayDriver = new ArrayDriver(new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$arrayDriver->isLeaf([5]);
$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('dataForFilter');
Expand All @@ -49,7 +32,7 @@ public function testIsLeafWithSnap()

public function testNormalise()
{
$arrayDriver = new ArrayDriver(new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$result = $arrayDriver->normalise($control = ['value']);
$result2 = $arrayDriver->normalise($control2 = 'string');
self::assertEquals($result, $control);
Expand All @@ -58,7 +41,7 @@ public function testNormalise()

public function testGetDataFotFilter()
{
$arrayDriver = new ArrayDriver(new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$arrayDriver->isLeaf([5]);
self::assertEquals($arrayDriver->getDataForFilter(), [0 => 5]);
$arrayDriver->isLeaf([[5]]);
Expand All @@ -67,7 +50,7 @@ public function testGetDataFotFilter()

public function testParse()
{
$arrayDriver = new ArrayDriver(new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$control = [
[0 => 'zero'],
[1 => 'zero'],
Expand Down Expand Up @@ -104,15 +87,9 @@ public function testParse()

public function testInstallDependencyContext()
{
$arrayDriver = new ArrayDriver($factory = new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$arrayDriver->beforeSearch();

$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('nodeFactory');
$property->setAccessible(true);
$objectValue = $property->getValue($arrayDriver);
self::assertSame($objectValue, $factory);

$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('dataForFilter');
$property->setAccessible(true);
Expand All @@ -122,15 +99,9 @@ public function testInstallDependencyContext()

public function testSetDetect()
{
$arrayDriver = new ArrayDriver($factory = new DummyNodeFactory());
$arrayDriver = new ArrayDriver();
$arrayDriver->setDetect(['value']);

$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('nodeFactory');
$property->setAccessible(true);
$objectValue = $property->getValue($arrayDriver);
self::assertSame($objectValue, $factory);

$reflection = new \ReflectionObject($arrayDriver);
$property = $reflection->getProperty('dataForFilter');
$property->setAccessible(true);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BreadthTraversalStrategy/BreadthStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -38,7 +38,7 @@ public function setUp(): void
public function testDetect($array, $expectedLeaf, $expectedNodes)
{
$verifier = new Verifier();
$this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier, $this->provider);
$this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
self::assertEquals($this->leafCounter, count($expectedLeaf));
self::assertEquals($this->nodeCounter, count($expectedNodes));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testDetect()
$verifier = new Verifier();
$provider = new TestCaseProviderVisitor($this);
$strategy = new BreadthStrategy();
$driver = new ArrayDriver(new DummyNodeFactory());
$driver = new ArrayDriver();

$strategy->setStop(true);
$strategy->detect([
Expand All @@ -42,7 +42,7 @@ public function testDetect()
],
4
],
], $driver, $verifier, $verifier, $provider);
], $driver, new DummyNodeFactory(), $verifier, $verifier, $provider);

self::assertTrue(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -33,7 +33,7 @@ public function setUp(): void
public function testDetect($array)
{
$verifier = new Verifier();
$this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier, $this->provider);
$this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
}

public function getCase()
Expand Down
26 changes: 25 additions & 1 deletion tests/Unit/Scanner/ScannerSnapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Vinograd\Scanner\ArrayDriver;
use Vinograd\Scanner\Driver;
use Vinograd\Scanner\Exception\ConfigurationException;
use Vinograd\Scanner\NodeFactory;
use Vinograd\Scanner\Scanner;
use PHPUnit\Framework\TestCase;
use Vinograd\Scanner\SingleStrategy;
Expand Down Expand Up @@ -50,6 +51,12 @@ public function testConstruct()
$property->setAccessible(true);
$objectValue = $property->getValue($scanner);
self::assertEmpty($objectValue);

$reflection = new \ReflectionObject($scanner);
$property = $reflection->getProperty('nodeFactory');
$property->setAccessible(true);
$objectValue = $property->getValue($scanner);
self::assertEmpty($objectValue);
}

public function testSetStrategy()
Expand Down Expand Up @@ -79,10 +86,17 @@ public function testSetVisitor()
public function testSetDriver()
{
$scanner = new Scanner();
$scanner->setDriver($driver = new ArrayDriver(new DummyNodeFactory()));
$scanner->setDriver($driver = new ArrayDriver());
self::assertSame($driver, $scanner->getDriver());
}

public function testGetNodeFactory()
{
$scanner = new Scanner();
$scanner->setNodeFactory($nodeFactory = $this->getMockForAbstractClass(NodeFactory::class));
self::assertSame($nodeFactory, $scanner->getNodeFactory());
}

public function testSearchNoDriver()
{
$this->expectException(ConfigurationException::class);
Expand All @@ -109,4 +123,14 @@ public function testSearchNoVisitor()
$scanner->setStrategy(new SingleStrategy());
$scanner->search([]);
}

public function testSearchNoNodeFactory()
{
$this->expectException(ConfigurationException::class);
$scanner = new Scanner();
$scanner->setDriver($this->getMockForAbstractClass(Driver::class));
$scanner->setStrategy(new SingleStrategy());
$scanner->setVisitor(new DummyVisitor());
$scanner->search([]);
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Scanner/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -40,6 +40,7 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
$scanner->setNodeFactory($this->factory);
$scanner->search($array);

self::assertCount($this->leafCounter, $expectedLeaf);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Scanner/SearchWithLeafFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -41,6 +41,7 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
$scanner->setNodeFactory($this->factory);

$scanner->addLeafFilter(new class() implements Filter {

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Scanner/SearchWithNodeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
{
$provider = new TestCaseProviderVisitor($this);
$strategy = new BreadthStrategy();
$driver = new ArrayDriver(new DummyNodeFactory());
$driver = new ArrayDriver();

$scanner = new Scanner();
$scanner->setStrategy($strategy);
$scanner->setVisitor($provider);
$scanner->setDriver($driver);
$scanner->setNodeFactory(new DummyNodeFactory());

$scanner->addNodeFilter(new class() implements Filter {

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Scanner/SearchWithResetLeafFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new BreadthStrategy();;
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -41,6 +41,7 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
$scanner->setStrategy($this->strategy);
$scanner->setVisitor($this->provider);
$scanner->setDriver($this->driver);
$scanner->setNodeFactory($this->factory);

$scanner->addLeafFilter(new class() implements Filter {

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Scanner/SearchWithResetNodeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public function testSearch($array, $expectedLeaf, $expectedNodes)
{
$provider = new TestCaseProviderVisitor($this);
$strategy = new BreadthStrategy();
$driver = new ArrayDriver(new DummyNodeFactory());
$driver = new ArrayDriver();

$scanner = new Scanner();
$scanner->setStrategy($strategy);
$scanner->setVisitor($provider);
$scanner->setDriver($driver);
$scanner->setNodeFactory(new DummyNodeFactory());

$scanner->addNodeFilter(new class() implements Filter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new SingleStrategy();
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
$this->verifier1 = new Verifier();
$this->verifier2 = new Verifier();
}
Expand All @@ -37,7 +37,7 @@ public function setUp(): void
public function testDetect($array)
{
$this->detect = $array;
$this->strategy->detect($array, $this->driver, $this->verifier1, $this->verifier2, $this->provider);
$this->strategy->detect($array, $this->driver, $this->factory, $this->verifier1, $this->verifier2, $this->provider);
}

public function getCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp(): void
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new SingleStrategy();
$this->factory = new DummyNodeFactory();
$this->driver = new ArrayDriver($this->factory);
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -37,7 +37,7 @@ public function testDetect($array, $except)
$this->array = $array;
$this->except = $except;
$verifier = new Verifier();
$this->strategy->detect($this->detect = $array, $this->driver, $verifier, $verifier,$this->provider);
$this->strategy->detect($this->detect = $array, $this->driver, $this->factory, $verifier, $verifier, $this->provider);
}

public function getCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testDetect()
{
$provider = new TestCaseProviderVisitor($this);
$strategy = new SingleStrategy();
$driver = new ArrayDriver(new DummyNodeFactory());
$driver = new ArrayDriver();
$verifier = new Verifier();

$strategy->setStop(true);
Expand All @@ -29,7 +29,7 @@ public function testDetect()
'key2' => 'value2',
'key3' => [4.5, 4],
'key4' => [1, 3, 2]
], $driver, $verifier, $verifier, $provider);
], $driver,new DummyNodeFactory(), $verifier, $verifier, $provider);

self::assertTrue(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setUp(): void
{
$this->provider = new TestCaseProviderVisitor($this);
$this->strategy = new SingleStrategy();
$this->driver = new ArrayDriver(new DummyNodeFactory());
$this->driver = new ArrayDriver();
}

/**
Expand All @@ -32,7 +32,7 @@ public function testDetect($array, $found)
{
$this->found = $found;
$verifier = new Verifier();
$this->strategy->detect( $array, $this->driver, $verifier, $verifier,$this->provider);
$this->strategy->detect( $array, $this->driver,new DummyNodeFactory(), $verifier, $verifier,$this->provider);
}

public function getCase()
Expand Down
Loading

0 comments on commit 5839aba

Please sign in to comment.