import axiom without dependency on symfony console
Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit

This commit is contained in:
2020-06-21 07:36:31 -04:00
parent 348d17cdd3
commit fb619dccbf
27 changed files with 2608 additions and 829 deletions

View File

@@ -0,0 +1,37 @@
<?php
use Enzyme\Axiom\Atoms\IntegerAtom;
class IntegerAtomTest extends PHPUnit_Framework_TestCase
{
public function test_atom_stores_correct_base_value()
{
$expected = 5;
$atom = new IntegerAtom($expected);
$this->assertEquals($expected, $atom->getValue());
$expected = 25;
$atom = new IntegerAtom($expected);
$this->assertEquals($expected, $atom->getValue());
$expected = PHP_INT_MAX;
$atom = new IntegerAtom($expected);
$this->assertEquals($expected, $atom->getValue());
}
/**
* @expectedException \Enzyme\Axiom\Exceptions\AtomException
*/
public function test_atom_throws_exception_when_initialised_with_invalid_value()
{
new IntegerAtom('foobar');
}
/**
* @expectedException \Enzyme\Axiom\Exceptions\AtomException
*/
public function test_atom_throws_exception_when_initialised_with_floating_value()
{
new IntegerAtom(100.5);
}
}

View File

@@ -0,0 +1,29 @@
<?php
use Enzyme\Axiom\Atoms\StringAtom;
class StringAtomTest extends PHPUnit_Framework_TestCase
{
public function test_atom_stores_correct_base_value()
{
$expected = 'Foo Bar';
$atom = new StringAtom($expected);
$this->assertEquals($expected, $atom->getValue());
$expected = '25';
$atom = new StringAtom($expected);
$this->assertEquals($expected, $atom->getValue());
$expected = '';
$atom = new StringAtom($expected);
$this->assertEquals($expected, $atom->getValue());
}
/**
* @expectedException \Enzyme\Axiom\Exceptions\AtomException
*/
public function test_atom_throws_exception_when_initialised_with_invalid_value()
{
new StringAtom(5);
}
}

View File

@@ -0,0 +1,34 @@
<?php
use Enzyme\Axiom\Bags\ArrayBag;
class ArrayBagTest extends PHPUnit_Framework_TestCase
{
public function test_bag_stores_value_as_expected()
{
$expected = 'Bar';
$bag = new ArrayBag(['foo' => $expected]);
$this->assertEquals($expected, $bag->get('foo'));
}
public function test_bag_returns_null_for_unknown_key()
{
$expected = null;
$bag = new ArrayBag(['foo' => 'bar']);
$this->assertEquals($expected, $bag->get('PHP'));
}
public function test_bag_stores_values_as_expected()
{
$expected = ['foo' => 'Bar', 'PHP' => 'Rulez'];
$bag = new ArrayBag($expected);
$this->assertEquals($expected, $bag->getAll());
}
public function test_bag_reports_stored_value_as_expected()
{
$expected = true;
$bag = new ArrayBag(['foo' => 'bar']);
$this->assertEquals($expected, $bag->has('foo'));
}
}

View File

@@ -0,0 +1,96 @@
<?php
use Enzyme\Axiom\Console\Config;
use Enzyme\Freckle\Dot;
use Mockery as m;
use Symfony\Component\Yaml\Parser;
class ConfigTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function test_config_returns_early_when_file_does_not_exist()
{
$file = 'fake.yaml';
$file_dispatch = m::mock(
'Enzyme\Parrot\File[exists]',
function ($mock) use ($file) {
$mock
->shouldReceive('exists')
->with($file)
->times(1)
->andReturn(false);
}
);
$config = new Config(new Parser, $file_dispatch, new Dot);
$config->parse($file);
}
public function test_config_stores_correct_values_from_valid_yaml_file()
{
$file = 'fake.yaml';
$contents = "repositories:\n";
$contents .= " - location: ~/Code/Acme/src/Repos\n";
$contents .= " - namespace: Acme\Repos\n";
$file_dispatch = m::mock(
'Enzyme\Parrot\File[exists,getContents]',
function ($mock) use ($file, $contents) {
$mock
->shouldReceive('exists')
->with($file)
->times(1)
->andReturn(true);
$mock
->shouldReceive('getContents')
->with($file)
->times(1)
->andReturn($contents);
}
);
$config = new Config(new Parser, $file_dispatch, new Dot);
$config->parse($file);
$expected = '~/Code/Acme/src/Repos';
$actual = $config->get('repositories.location');
$this->assertEquals($expected, $actual);
}
/**
* @expectedException InvalidArgumentException
*/
public function test_config_throws_exception_on_bad_yaml_parse()
{
$file = 'fake.yaml';
$parser = m::mock(
'Symfony\Component\Yaml\Parser[parse]',
function ($mock) {
$mock
->shouldReceive('parse')
->andThrow(new InvalidArgumentException('oops'));
}
);
$file_dispatch = m::mock(
'Enzyme\Parrot\File[exists,getContents]',
function ($mock) use ($file) {
$mock
->shouldReceive('exists')
->with($file)
->times(1)
->andReturn(true);
$mock
->shouldReceive('getContents')
->with($file)
->times(1)
->andReturn('bad');
}
);
$config = new Config($parser, $file_dispatch, new Dot);
$config->parse($file);
}
}

View File

@@ -0,0 +1,33 @@
<?php
use Enzyme\Axiom\Reports\SimpleReport;
class SimpleReportTest extends PHPUnit_Framework_TestCase
{
public function test_report_stores_message_as_expected()
{
$expected = 'Something went wrong.';
$report = new SimpleReport($expected);
$this->assertEquals($expected, $report->getMessage());
}
public function test_report_stores_details_as_expected()
{
$expected = ['tests' => 'required'];
$report = new SimpleReport('Foo Bar went pear shaped.', $expected);
$this->assertEquals($expected, $report->getDetails());
}
public function test_report_reports_details_as_expected()
{
$expected = true;
$report = new SimpleReport(
'It went pear shaped again.', ['tests' => 'required']
);
$this->assertEquals($expected, $report->hasDetails());
$expected = false;
$report = new SimpleReport('Foo Bar went pear shaped.');
$this->assertEquals($expected, $report->hasDetails());
}
}

View File

@@ -0,0 +1,79 @@
<?php
use Enzyme\Axiom\Atoms\IntegerAtom;
use Enzyme\Axiom\Bags\ArrayBag;
use Enzyme\Axiom\Repositories\InMemoryRepository;
use Mockery as m;
class InMemoryRepositoryTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function test_repository_stores_models_as_expected()
{
$identity = 0;
$factory = m::mock('Enzyme\Axiom\Factories\FactoryInterface');
$model = m::mock('Enzyme\Axiom\Models\ModelInterface', function ($mock) use ($identity) {
$mock->shouldReceive('identity')->once()->andReturn($identity);
});
$repo = new InMemoryRepository($factory);
$repo->add($model);
// Let's make sure the repo reports the new model as existing.
$expected = true;
$this->assertEquals($expected, $repo->has(new IntegerAtom($identity)));
// And make sure it returns the new model as expected.
$expected = $model;
$this->assertEquals($expected, $repo->getById(new IntegerAtom($identity)));
// And that the new model is the only model currently associated with this repo.
$expected = [$model];
$this->assertEquals($expected, $repo->getAll());
}
public function test_repository_removes_models_as_expected()
{
$identity = 0;
$factory = m::mock('Enzyme\Axiom\Factories\FactoryInterface');
$model = m::mock('Enzyme\Axiom\Models\ModelInterface', function ($mock) use ($identity) {
$mock->shouldReceive('identity')->once()->andReturn($identity);
});
$repo = new InMemoryRepository($factory);
$repo->add($model);
$repo->removeById(new IntegerAtom($identity));
// Let's make sure the repo reports the model as non-existent.
$expected = false;
$this->assertEquals($expected, $repo->has(new IntegerAtom($identity)));
// And make sure it returns null if the model is requested.
$expected = null;
$this->assertEquals($expected, $repo->getById(new IntegerAtom($identity)));
// And that the new model is not currently associated with this repo's collection.
$expected = [];
$this->assertEquals($expected, $repo->getAll());
}
public function test_repository_delegates_updates_to_factory_dependency_as_expected()
{
$identity = 0;
$model = m::mock('Enzyme\Axiom\Models\ModelInterface', function ($mock) use ($identity) {
$mock->shouldReceive('identity')->andReturn($identity);
});
$bag = new ArrayBag([]);
$factory = m::mock('Enzyme\Axiom\Factories\FactoryInterface', function ($mock) use ($model, $bag) {
$mock->shouldReceive('update')->once()->with($model, $bag)->andReturn($model);
});
$repo = new InMemoryRepository($factory);
$repo->add($model);
$repo->update($model, $bag);
}
}

56
axiom_tests/phpunit.xml Normal file
View File

@@ -0,0 +1,56 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="true">
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">console</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="Console Test Suite">
<directory>tests/Console</directory>
</testsuite>
<testsuite name="Atoms Test Suite">
<directory>tests/Atoms</directory>
</testsuite>
<testsuite name="Bags Test Suite">
<directory>tests/Bags</directory>
</testsuite>
<testsuite name="Reports Test Suite">
<directory>tests/Reports</directory>
</testsuite>
<testsuite name="Repositories Test Suite">
<directory>tests/Repositories</directory>
</testsuite>
</testsuites>
</phpunit>