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,13 @@
<?php
namespace Enzyme\Axiom\Atoms;
interface AtomInterface
{
/**
* Get the underlying value associated with this atom.
*
* @return mixed
*/
public function getValue();
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Enzyme\Axiom\Atoms;
use Enzyme\Axiom\Exceptions\AtomException;
class IntegerAtom implements AtomInterface
{
protected $value;
public function __construct($value)
{
if ($this->isInvalidOrFloat($value)) {
throw new AtomException(get_class($this), $value);
}
$this->value = (int)$value;
}
protected function isInvalidOrFloat($value)
{
return is_numeric($value) === false || is_float($value) === true;
}
public function getValue()
{
return $this->value;
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Enzyme\Axiom\Atoms;
use Enzyme\Axiom\Exceptions\AtomException;
class StringAtom implements AtomInterface
{
protected $value;
public function __construct($value)
{
if (is_string($value) === false) {
throw new AtomException(get_class($this), $value);
}
$this->value = $value;
}
public function getValue()
{
return $this->value;
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Enzyme\Axiom\Bags;
class ArrayBag implements BagInterface
{
protected $store;
public function __construct(array $store)
{
$this->store = $store;
}
public function get($key)
{
if ($this->has($key)) {
return $this->store[$key];
}
return null;
}
public function has($key)
{
return isset($this->store[$key])
&& array_key_exists($key, $this->store);
}
public function getAll()
{
return $this->store;
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Enzyme\Axiom\Bags;
interface BagInterface
{
/**
* Get the value associated with the given key. If the key does not
* exist, return null instead.
*
* @param string $key
*
* @return mixed
*/
public function get($key);
/**
* Get all the key/value pairs for this bag.
*
* @return array
*/
public function getAll();
/**
* Check whether there is a value associated with the given key.
*
* @param string $key
*
* @return boolean
*/
public function has($key);
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Enzyme\Axiom\Exceptions;
class AtomException extends AxiomException
{
public function __construct($class, $value)
{
parent::__construct(
"The atom [{$class}] could not process the value [{$value}]."
);
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Enzyme\Axiom\Exceptions;
use Exception;
class AxiomException extends Exception
{
//
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Enzyme\Axiom\Factories;
use Enzyme\Axiom\Bags\BagInterface;
use Enzyme\Axiom\Models\ModelInterface;
interface FactoryInterface
{
/**
* Make a new model given the data provided.
*
* @param BagInterface $data
*
* @return \Enzyme\Axiom\Models\ModelInterface
*/
public function make(BagInterface $data);
/**
* Update the model provided with the given data.
*
* @param ModelInterface $model
* @param BagInterface $data
*
* @return \Enzyme\Axiom\Models\ModelInterface
*/
public function update(ModelInterface $model, BagInterface $data);
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Enzyme\Axiom\Models;
interface ModelInterface
{
/**
* Get the unique identity for this mode.
*
* @return int
*/
public function identity();
/**
* Checks whether this model has the given attribute set.
*
* @param string $attribute
*
* @return boolean
*/
public function has($attribute);
/**
* Get the value associated with the given attribute.
*
* @param string $attribute
*
* @return mixed
*/
public function get($attribute);
/**
* Get all the attributes associated with this model.
*
* @return array
*/
public function getAll();
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Enzyme\Axiom\Recipients;
use Enzyme\Axiom\Models\ModelInterface;
use Enzyme\Axiom\Reports\ReportInterface;
interface OnCreateRecipientInterface
{
/**
* Called when the creation of a model was a success.
*
* @param ModelInterface $model The newly created model.
*
* @return mixed
*/
public function onCreateSuccess(ModelInterface $model);
/**
* Called when the creation of a model was a failure.
*
* @param ReportInterface $report The failure report.
*
* @return mixed
*/
public function onCreateFailure(ReportInterface $report);
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Enzyme\Axiom\Recipients;
use Enzyme\Axiom\Models\ModelInterface;
use Enzyme\Axiom\Reports\ReportInterface;
interface OnDeleteRecipientInterface
{
/**
* Called when the deletion of a model was a success.
*
* @param ModelInterface $model A shell copy of the deleted model.
*
* @return mixed
*/
public function onDeleteSuccess(ModelInterface $model);
/**
* Called when the deletion of a model was a failure.
*
* @param ReportInterface $report The failure report.
*
* @return mixed
*/
public function onDeleteFailure(ReportInterface $report);
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Enzyme\Axiom\Recipients;
use Enzyme\Axiom\Models\ModelInterface;
use Enzyme\Axiom\Reports\ReportInterface;
interface OnUpdateRecipientInterface
{
/**
* Called when the modification of a model was a success.
*
* @param ModelInterface $model The updated model.
*
* @return mixed
*/
public function onUpdateSuccess(ModelInterface $model);
/**
* Called when the modification of a model was a failure.
*
* @param ReportInterface $report The failure report.
*
* @return mixed
*/
public function onUpdateFailure(ReportInterface $report);
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Enzyme\Axiom\Reports;
class FailureReport extends SimpleReport
{
//
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Enzyme\Axiom\Reports;
interface ReportInterface
{
/**
* Get the human readable message associated with this report.
*
* @return string
*/
public function getMessage();
/**
* Whether this report has additional details.
*
* @return boolean
*/
public function hasDetails();
/**
* Get the additional details associated with this report.
*
* @return array
*/
public function getDetails();
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Enzyme\Axiom\Reports;
class SimpleReport implements ReportInterface
{
protected $message;
protected $details;
public function __construct($message, $details = [])
{
$this->message = $message;
$this->details = $details;
}
public function getMessage()
{
return $this->message;
}
public function hasDetails()
{
return count($this->details) > 0;
}
public function getDetails()
{
return $this->details;
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Enzyme\Axiom\Repositories;
use Enzyme\Axiom\Atoms\AtomInterface;
use Enzyme\Axiom\Bags\BagInterface;
use Enzyme\Axiom\Factories\FactoryInterface;
use Enzyme\Axiom\Models\ModelInterface;
class InMemoryRepository implements RepositoryInterface
{
protected $factory;
protected $store;
public function __construct(FactoryInterface $factory)
{
$this->factory = $factory;
$this->store = [];
}
public function add(ModelInterface $model)
{
$this->store[$model->identity()] = $model;
}
public function removeById(AtomInterface $id)
{
if ($this->has($id)) {
unset($this->store[$id->getValue()]);
}
}
public function has(AtomInterface $id)
{
return isset($this->store[$id->getValue()])
&& array_key_exists($id->getValue(), $this->store);
}
public function update(ModelInterface $model, BagInterface $data)
{
$updated_model = $this->factory->update($model, $data);
$this->store[$model->identity()] = $updated_model;
}
public function getById(AtomInterface $id)
{
return $this->has($id)
? $this->store[$id->getValue()]
: null;
}
public function getAll()
{
return $this->store;
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Enzyme\Axiom\Repositories;
use Enzyme\Axiom\Atoms\AtomInterface;
use Enzyme\Axiom\Bags\BagInterface;
use Enzyme\Axiom\Models\ModelInterface;
interface RepositoryInterface
{
/**
* Add the given model to the repository.
*
* @param ModelInterface $model
*/
public function add(ModelInterface $model);
/**
* Remove the model with the given ID from the repository.
*
* @param AtomInterface $id
*
* @return void
*/
public function removeById(AtomInterface $id);
/**
* Update the given model with the supplied data.
*
* @param ModelInterface $model
* @param BagInterface $data
*
* @return \Enzyme\Axiom\Models\ModelInterface
*/
public function update(ModelInterface $model, BagInterface $data);
/**
* Get the model associated with the given ID.
*
* @param AtomInterface $id
*
* @return \Enzyme\Axiom\Models\ModelInterface
*/
public function getById(AtomInterface $id);
/**
* Get all models from this repository.
*
* @return array
*/
public function getAll();
/**
* Check whether this repository has a model associated with the given ID.
*
* @param AtomInterface $id
*
* @return boolean
*/
public function has(AtomInterface $id);
}

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>

View File

@@ -11,9 +11,10 @@
], ],
"require": { "require": {
"php": ">=7.1", "php": ">=7.1",
"enzyme/axiom": "^4.2",
"enzyme/collection": "^1.0", "enzyme/collection": "^1.0",
"enzyme/freckle": "^0.3.0", "enzyme/freckle": "^0.3.0",
"enzyme/parrot": "^0.0.2",
"icanboogie/inflector": "^1.4",
"illuminate/database": "^5.6", "illuminate/database": "^5.6",
"illuminate/pipeline": "^5.6", "illuminate/pipeline": "^5.6",
"league/pipeline": "^1.0", "league/pipeline": "^1.0",
@@ -23,7 +24,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"XaiCorp\\AbcParser\\": "src/" "XaiCorp\\AbcParser\\": "src/",
"Enzyme\\Axiom\\": "axiom_src/"
} }
}, },
"autoload-dev": { "autoload-dev": {

2491
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
<?php //[STAMP] 07a082bc9ef10ba5dbed4c8c41052c54 <?php //[STAMP] d8caeee7956924d9e7b2dc1aaf1abb70
namespace _generated; namespace _generated;
// This class was automatically generated by build task // This class was automatically generated by build task
@@ -25,19 +25,19 @@ trait UnitTesterActions
* Regular example: * Regular example:
* ```php * ```php
* <?php * <?php
* $I->assertEquals($element->getChildrenCount(), 5); * $I->assertEquals(5, $element->getChildrenCount());
* ``` * ```
* *
* Floating-point example: * Floating-point example:
* ```php * ```php
* <?php * <?php
* $I->assertEquals($calculator->add(0.1, 0.2), 0.3, 'Calculator should add the two numbers correctly.', 0.01); * $I->assertEquals(0.3, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ``` * ```
* *
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
* @param float $delta * @param float $delta
* @see \Codeception\Module\Asserts::assertEquals() * @see \Codeception\Module\Asserts::assertEquals()
*/ */
public function assertEquals($expected, $actual, $message = null, $delta = null) { public function assertEquals($expected, $actual, $message = null, $delta = null) {
@@ -55,19 +55,19 @@ trait UnitTesterActions
* Regular example: * Regular example:
* ```php * ```php
* <?php * <?php
* $I->assertNotEquals($element->getChildrenCount(), 0); * $I->assertNotEquals(0, $element->getChildrenCount());
* ``` * ```
* *
* Floating-point example: * Floating-point example:
* ```php * ```php
* <?php * <?php
* $I->assertNotEquals($calculator->add(0.1, 0.2), 0.4, 'Calculator should add the two numbers correctly.', 0.01); * $I->assertNotEquals(0.4, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ``` * ```
* *
* @param $expected * @param $expected
* @param $actual * @param $actual
* @param string $message * @param string $message
* @param float $delta * @param float $delta
* @see \Codeception\Module\Asserts::assertNotEquals() * @see \Codeception\Module\Asserts::assertNotEquals()
*/ */
public function assertNotEquals($expected, $actual, $message = null, $delta = null) { public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
@@ -320,11 +320,27 @@ trait UnitTesterActions
* @param string $message * @param string $message
* @see \Codeception\Module\Asserts::assertTrue() * @see \Codeception\Module\Asserts::assertTrue()
*/ */
public function assertTrue($condition, $message = null) { public function assertTrue($condition, $message = null)
{
return $this->getScenario()->runStep(new Action('assertTrue', func_get_args())); return $this->getScenario()->runStep(new Action('assertTrue', func_get_args()));
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT true (everything but true)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotTrue()
*/
public function assertNotTrue($condition, $message = null)
{
return $this->getScenario()->runStep(new Action('assertNotTrue', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@@ -334,11 +350,27 @@ trait UnitTesterActions
* @param string $message * @param string $message
* @see \Codeception\Module\Asserts::assertFalse() * @see \Codeception\Module\Asserts::assertFalse()
*/ */
public function assertFalse($condition, $message = null) { public function assertFalse($condition, $message = null)
{
return $this->getScenario()->runStep(new Action('assertFalse', func_get_args())); return $this->getScenario()->runStep(new Action('assertFalse', func_get_args()));
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT false (everything but false)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotFalse()
*/
public function assertNotFalse($condition, $message = null)
{
return $this->getScenario()->runStep(new Action('assertNotFalse', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
@@ -539,20 +571,59 @@ trait UnitTesterActions
* *
* @param $exception string or \Exception * @param $exception string or \Exception
* @param $callback * @param $callback
*
* @deprecated Use expectThrowable instead
* @see \Codeception\Module\Asserts::expectException() * @see \Codeception\Module\Asserts::expectException()
*/ */
public function expectException($exception, $callback) { public function expectException($exception, $callback)
{
return $this->getScenario()->runStep(new Action('expectException', func_get_args())); return $this->getScenario()->runStep(new Action('expectException', func_get_args()));
} }
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks throwables (Exceptions/Errors) called inside the callback function.
* Either throwable class name or throwable instance should be provided.
*
* ```php
* <?php
* $I->expectThrowable(MyThrowable::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectThrowable(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or throwable code, you can pass them with throwable instance:
* ```php
* <?php
* // will check that throwable MyError is thrown with "Don't do bad things" message
* $I->expectThrowable(new MyError("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $throwable string or \Throwable
* @param $callback
* @see \Codeception\Module\Asserts::expectThrowable()
*/
public function expectThrowable($throwable, $callback)
{
return $this->getScenario()->runStep(new Action('expectThrowable', func_get_args()));
}
/** /**
* [!] Method is generated. Documentation taken from corresponding module. * [!] Method is generated. Documentation taken from corresponding module.
* *
* *
* @see \Helper\ExtraAsserts::assertCanSave() * @see \Helper\ExtraAsserts::assertCanSave()
*/ */
public function assertCanSave($model) { public function assertCanSave($model)
{
return $this->getScenario()->runStep(new Action('assertCanSave', func_get_args())); return $this->getScenario()->runStep(new Action('assertCanSave', func_get_args()));
} }