1: <?php
2: /**
3: * This file is part of the Autarky package.
4: *
5: * (c) Andreas Lutro <anlutro@gmail.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: namespace Autarky\Testing;
12:
13: use PHPUnit_Framework_TestCase;
14:
15: /**
16: * Abstract test case that makes for easy functional testing of your application
17: * at the controller level.
18: */
19: abstract class TestCase extends PHPUnit_Framework_TestCase
20: {
21: /**
22: * The application instance.
23: *
24: * @var \Autarky\Application
25: */
26: protected $app;
27:
28: /**
29: * {@inheritdoc}
30: */
31: public function setUp()
32: {
33: $this->app = $this->createApplication();
34: $this->app->setEnvironment('testing');
35: $this->app->boot();
36: $this->app->getErrorHandler()->setRethrow(true);
37: }
38:
39: /**
40: * Enable exception handling in the application being tested.
41: *
42: * By default, uncaught exceptions in the application will simply be thrown
43: * again, meaning you have to call `setExpectedException` or similar if an
44: * exception is expected behaviour. If instead you want the application
45: * error handler to do its job and return a response, call this method.
46: *
47: * @return void
48: */
49: protected function enableExceptionHandling()
50: {
51: $this->app->getErrorHandler()->setRethrow(false);
52: }
53:
54: /**
55: * {@inheritdoc}
56: */
57: public function tearDown()
58: {
59: $this->app = null;
60: }
61:
62: /**
63: * Create and return the application instance.
64: *
65: * Usually this will simply be a require of your app/start.php file. Make
66: * sure that this file does return $app; at the end.
67: *
68: * @return \Autarky\Application
69: */
70: abstract protected function createApplication();
71: }
72: