Last active
December 28, 2015 11:49
-
-
Save simkimsia/7496713 to your computer and use it in GitHub Desktop.
Template for Behavior Test in CakePHP Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * | |
| * {ExampleBehavior}BehaviorTest file | |
| * | |
| * PHP 5 | |
| * | |
| * Copyright {copyright year}, {maintainer} | |
| * {Location} | |
| * | |
| * Licensed under The MIT License | |
| * Redistributions of files must retain the above copyright notice. | |
| * | |
| * @copyright Copyright {copyright year}, {maintainer} | |
| * @link {website} | |
| * @author {maintainer} <{maintainer email}> | |
| * @license http://www.opensource.org/licenses/mit-license.php The MIT License | |
| * @package {PluginName} | |
| * @subpackage {PluginName}.Test.Case.Model.Behavior | |
| * @version 0.1.0 | |
| */ | |
| App::uses('Model', 'Model'); | |
| App::uses('AppModel', 'Model'); | |
| require_once dirname(dirname(__FILE__)) . DS . 'mock_models.php'; | |
| /** | |
| * {ExampleBehavior}Test class | |
| * | |
| */ | |
| class {ExampleBehavior}BehaviorTest extends CakeTestCase { | |
| public $fixtures = array( | |
| 'plugin.{plugin_name}.{example_model}' | |
| ); | |
| /** | |
| * Method executed before each test | |
| * | |
| */ | |
| public function setUp() { | |
| parent::setUp(); | |
| $this->{ExampleModel} = ClassRegistry::init('{ExampleModel}'); | |
| // create relations between any of the models inside mock_models.php | |
| // here | |
| $this->{ExampleModel}->Behaviors->attach('{PluginName}.{ExampleBehavior}'); | |
| } | |
| /** | |
| * Method executed after each test | |
| * | |
| */ | |
| public function tearDown() { | |
| unset($this->{ExampleModel}); | |
| parent::tearDown(); | |
| } | |
| /** | |
| * test{ExampleMethod} method | |
| * | |
| * @return void | |
| */ | |
| public function test{ExampleMethod}() { | |
| // GIVEN setup | |
| // WHEN we execute {ExampleMethod} | |
| $result = $this->{ExampleModel}->{ExampleMethod}(); | |
| // THEN we expect | |
| $expected = null; | |
| $this->assertEquals($expected, $result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment