Repository URL to install this package:
|
Version:
2.2.0 ▾
|
<?php
namespace CrazyFactory\Jobs\Tests;
use CrazyFactory\Jobs\JobConfig;
class JobConfigTest extends \PHPUnit_Framework_TestCase
{
public function testToArray()
{
$exp = [
'enabled' => true,
'logError' => true,
];
$jobConfig = new JobConfig(array_slice($exp, 0));
$this->assertEquals($exp, $jobConfig->toArray());
}
public function testFromArray()
{
$exp = [
'enabled' => true,
'logError' => true,
];
$jobConfig = new JobConfig();
$jobConfig->fromArray(array_slice($exp, 0));
$this->assertEquals($exp, $jobConfig->toArray());
$jobConfig->fromArray(["foo" => true, "enabled" => false]);
$this->assertEquals([
"logError" => true,
"enabled" => false,
"foo" => true
], $jobConfig->toArray());
}
public function testGetDefault() {
$actual = array_keys(JobConfig::getDefault()->toArray());
sort($actual);
$this->assertEquals([
"enabled", "logError", "logSuccess", "maxRuntime", "processRuntimeEvery", "reportError", "reportSuccess", "singleton"
], $actual, "expected exactly these keys");
}
public function testMerge() {
$jobConfig = (new JobConfig(['a' => 0, 'b' => 1]))
->merge(new JobConfig(['b' => 15, 'c' => true]));
$this->assertEquals(['a' => 0, 'b' => 15, 'c' => true], $jobConfig->toArray());
}
public function testArrayAccess() {
$jobConfig = new JobConfig(['foo' => 'bar']);
// get
$this->assertEquals('bar', $jobConfig['foo']);
// no offest
$this->assertFalse(isset($jobConfig['apple']));
$this->assertTrue(isset($jobConfig['foo']));
// set
$jobConfig['apple'] = 'pie';
$this->assertEquals('pie', $jobConfig['apple']);
// deep check
$this->assertEquals(['foo' => 'bar', 'apple' => 'pie'], $jobConfig->toArray());
// unset
unset($jobConfig['apple']);
$this->assertFalse(isset($jobConfig['apple']));
$this->assertEquals(['foo' => 'bar'], $jobConfig->toArray());
}
}