From 1144df4023a6a59d6ff44b99945a140e307c703c Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Thu, 27 Nov 2014 20:42:12 +0000 Subject: [PATCH] Added basic controller unit tests --- .../Api/ComponentControllerTest.php | 33 +++++++++ app/tests/ExampleTest.php | 16 ----- composer.json | 3 +- composer.lock | 68 ++++++++++++++++++- 4 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 app/tests/Controllers/Api/ComponentControllerTest.php delete mode 100644 app/tests/ExampleTest.php diff --git a/app/tests/Controllers/Api/ComponentControllerTest.php b/app/tests/Controllers/Api/ComponentControllerTest.php new file mode 100644 index 00000000..c45e52ee --- /dev/null +++ b/app/tests/Controllers/Api/ComponentControllerTest.php @@ -0,0 +1,33 @@ +repo = Mockery::mock('CachetHQ\Cachet\Repositories\Component\ComponentRepository'); + $this->dingo = Mockery::mock('Dingo\Api\Auth\Shield'); + } + + public function tearDown() { + Mockery::close(); + } + + public function test_get_components_method() + { + $this->repo->shouldReceive('all')->once()->andReturn('foo'); + + $controller = new CachetHQ\Cachet\Controllers\Api\ComponentController($this->dingo, $this->repo); + $response = $controller->getComponents(); + + $this->assertEquals('foo', $response); + } + + public function test_get_component_method() + { + $this->repo->shouldReceive('findOrFail')->with(1)->once()->andReturn('foo'); + + $controller = new CachetHQ\Cachet\Controllers\Api\ComponentController($this->dingo, $this->repo); + $response = $controller->getComponent(1); + + $this->assertEquals('foo', $response); + } +} \ No newline at end of file diff --git a/app/tests/ExampleTest.php b/app/tests/ExampleTest.php deleted file mode 100644 index ad2aed05..00000000 --- a/app/tests/ExampleTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->request('GET', '/'); - - $this->assertTrue($this->client->getResponse()->isOk()); - } -} \ No newline at end of file diff --git a/composer.json b/composer.json index 80194a27..f5ed8343 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ "thujohn/rss": "dev-master" }, "require-dev": { - "phpunit/phpunit": "~4.3.0" + "phpunit/phpunit": "~4.3.0", + "mockery/mockery": "0.9.*" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index c7579ec7..d6db6a83 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ae2cfb2f8386f3b5f6fd63b350807b5a", + "hash": "da2246ff474233efc51049860a882331", "packages": [ { "name": "classpreloader/classpreloader", @@ -2106,6 +2106,72 @@ ], "time": "2014-10-13 12:58:55" }, + { + "name": "mockery/mockery", + "version": "0.9.2", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "95a4855380dc70176c51807c678fb3bd6198529a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/95a4855380dc70176c51807c678fb3bd6198529a", + "reference": "95a4855380dc70176c51807c678fb3bd6198529a", + "shasum": "" + }, + "require": { + "lib-pcre": ">=7.0", + "php": ">=5.3.2" + }, + "require-dev": { + "hamcrest/hamcrest-php": "~1.1", + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.7@dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succint API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2014-09-03 10:11:10" + }, { "name": "phpunit/php-code-coverage", "version": "2.0.11",