Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added simple Starship example to examples directory

  • Loading branch information...
commit 21288d1305f26d57ce9e5241cfa29462665a6ff1 1 parent 181f02d
Padraic Brady authored
View
7 README.markdown
@@ -140,6 +140,13 @@ use the Mockery namespace with a shorter alias. For example:
}
}
+Mockery ships with an autoloader so you don't need to litter your tests with
+require_once() calls. To use it, ensure Mockery is on your include path and add
+the following to your test suite's Bootstrap or TestHelper file:
+
+ $loader = new \Mockery\Loader;
+ $loader->register();
+
Quick Reference
---------------
View
11 examples/starship/Bootstrap.php
@@ -0,0 +1,11 @@
+<?php
+
+set_include_path(
+ dirname(__FILE__) . '/../../library'
+ . PATH_SEPARATOR . get_include_path()
+);
+
+require_once 'Mockery/Loader.php';
+
+$loader = new \Mockery\Loader;
+$loader->register();
View
25 examples/starship/Starship.php
@@ -0,0 +1,25 @@
+<?php
+
+class Starship
+{
+
+ protected $_engineering = null;
+
+ public function __construct($engineering)
+ {
+ $this->_engineering = $engineering;
+ }
+
+ public function enterOrbit()
+ {
+ $this->_engineering->disengageWarp();
+ $this->_engineering->runDiagnosticLevel(5);
+ $this->_engineering->divertPower(0.40, 'sensors');
+ $this->_engineering->divertPower(0.30, 'auxengines');
+ $this->_engineering->runDiagnosticLevel(1);
+
+ // We can add more runDiagnosticLevel() calls without failing the test
+ // anywhere above since they are unordered.
+ }
+
+}
View
22 examples/starship/StarshipTest.php
@@ -0,0 +1,22 @@
+<?php
+
+use \Mockery as M;
+
+require_once 'Starship.php';
+
+class StarshipTest extends PHPUnit_Framework_TestCase
+{
+ public function testEngineeringResponseToEnteringOrbit()
+ {
+ $mock = M::mock('Engineering');
+ $mock->shouldReceive('disengageWarp')->once()->ordered();
+ $mock->shouldReceive('divertPower')->with(0.40, 'sensors')->once()->ordered();
+ $mock->shouldReceive('divertPower')->with(0.30, 'auxengines')->once()->ordered();
+ $mock->shouldReceive('runDiagnosticLevel')->with(1)->once()->ordered();
+ $mock->shouldReceive('runDiagnosticLevel')->with(M::type('int'))->zeroOrMoreTimes();
+
+ $starship = new Starship($mock);
+ $starship->enterOrbit();
+ }
+
+}
View
10 examples/starship/phpunit.xml
@@ -0,0 +1,10 @@
+<phpunit bootstrap="./Bootstrap.php">
+ <testsuite name="Starship Test Suite">
+ <directory>./</directory>
+ </testsuite>
+ <listeners>
+ <listener class="\Mockery\Adapter\Phpunit\TestListener"
+ file="Mockery/Adapter/Phpunit/TestListener.php">
+ </listener>
+ </listeners>
+</phpunit>
Please sign in to comment.
Something went wrong with that request. Please try again.