From cc65cc9cf176597f4f66acca7690bbbfac5a69e5 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Mon, 1 Aug 2016 14:38:23 -0400 Subject: [PATCH] Set up mutation testing for unit tests --- .gitignore | 3 ++- composer.json | 3 ++- humbug.json.dist | 12 ++++++++++++ phpunit.xml | 29 +++++++++++++++++++++++++++++ tests/Ion/ConfigTest.php | 4 +++- tests/Ion/Di/ContainerTest.php | 16 ++++++++++++++-- tests/Ion/Type/ArrayTypeTest.php | 9 +++++++++ 7 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 humbug.json.dist create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index 72c6903d..78031d83 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ app/config/*.toml !app/config/*.toml.example phinx.yml .idea/ -Caddyfile \ No newline at end of file +Caddyfile +build/humbuglog.txt \ No newline at end of file diff --git a/composer.json b/composer.json index 3a168e70..0a7b0777 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "phploc/phploc": "^3.0", "phpmd/phpmd": "^2.4", "phpunit/phpunit": "^5.4", - "robmorgan/phinx": "^0.6.4" + "robmorgan/phinx": "^0.6.4", + "humbug/humbug": "~1.0@dev" } } diff --git a/humbug.json.dist b/humbug.json.dist new file mode 100644 index 00000000..d1e38834 --- /dev/null +++ b/humbug.json.dist @@ -0,0 +1,12 @@ +{ + "source": { + "directories": [ + "src" + ] + }, + "timeout": 10, + "logs": { + "text": "build\/humbuglog.txt", + "json": "build\/humbug.json" + } +} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..6f5df955 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,29 @@ + + + + + src/Aviat/Ion + src/Aviat/AnimeClient + + + + + tests/Ion + + + tests/AnimeClient + + + + + + + + + + \ No newline at end of file diff --git a/tests/Ion/ConfigTest.php b/tests/Ion/ConfigTest.php index 3cd84de2..ca716cf8 100644 --- a/tests/Ion/ConfigTest.php +++ b/tests/Ion/ConfigTest.php @@ -23,7 +23,8 @@ class ConfigTest extends AnimeClient_TestCase { public function testConfigSet() { - $this->config->set('foo', 'foobar'); + $ret = $this->config->set('foo', 'foobar'); + $this->assertInstanceOf('Aviat\Ion\Config', $ret); $this->assertEquals('foobar', $this->config->get('foo')); $this->config->set(['apple', 'sauce', 'is'], 'great'); @@ -31,6 +32,7 @@ class ConfigTest extends AnimeClient_TestCase { $this->assertEquals('great', $apple['sauce']['is'], "Config value not set correctly"); $this->assertEquals('great', $this->config->get(['apple', 'sauce', 'is']), "Array argument get for config failed."); + } public function testConfigBadSet() diff --git a/tests/Ion/Di/ContainerTest.php b/tests/Ion/Di/ContainerTest.php index f4002582..bbf22627 100644 --- a/tests/Ion/Di/ContainerTest.php +++ b/tests/Ion/Di/ContainerTest.php @@ -51,6 +51,15 @@ class ContainerTest extends AnimeClient_TestCase { } } + public function testGetSet() + { + $container = $this->container->set('foo', function() {}); + + $this->assertInstanceOf('Aviat\Ion\Di\Container', $container); + $this->assertInstanceOf('Aviat\Ion\Di\ContainerInterface', $container); + $this->assertTrue(is_callable($container->get('foo'))); + } + public function testLoggerMethods() { // Does the container have the default logger? @@ -63,8 +72,11 @@ class ContainerTest extends AnimeClient_TestCase { $logger2->pushHandler(new TestHandler()); // Set the logger channels - $this->container->setLogger($logger1); - $this->container->setLogger($logger2, 'test'); + $container = $this->container->setLogger($logger1); + $container2 = $this->container->setLogger($logger2, 'test'); + + $this->assertInstanceOf('Aviat\Ion\Di\ContainerInterface', $container); + $this->assertInstanceOf('Aviat\Ion\Di\Container', $container2); $this->assertEquals($logger1, $this->container->getLogger('default')); $this->assertEquals($logger2, $this->container->getLogger('test')); diff --git a/tests/Ion/Type/ArrayTypeTest.php b/tests/Ion/Type/ArrayTypeTest.php index db2d56c6..e78315ee 100644 --- a/tests/Ion/Type/ArrayTypeTest.php +++ b/tests/Ion/Type/ArrayTypeTest.php @@ -79,6 +79,15 @@ class ArrayTypeTest extends AnimeClient_TestCase { $this->assertEquals($expected, $actual); } + public function testSet() + { + $obj = $this->arr([]); + $arraytype = $obj->set('foo', 'bar'); + + $this->assertInstanceOf('Aviat\Ion\Type\ArrayType', $arraytype); + $this->assertEquals('bar', $obj->get('foo')); + } + public function testGet() { $array = [1, 2, 3, 4, 5];