Skip to content

Commit

Permalink
use expecctations to test behaviors are called
Browse files Browse the repository at this point in the history
Test that x is called specifically - not that trying to call x doesn't
fail
  • Loading branch information
AD7six committed Nov 10, 2013
1 parent 90946c3 commit 5aff237
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions Cake/Test/TestCase/ORM/BehaviorRegistryTest.php
Expand Up @@ -173,12 +173,23 @@ public function testHasFinder() {
/**
* test call
*
* Setup a behavior, then replace it with a mock to verify methods are called.
* use dummy return values to verify the return value makes it back
*
* @return void
*/
public function testCall() {
$this->Behaviors->load('Sluggable');
$result = $this->Behaviors->call('slugify', ['some value']);
$this->assertEquals('some_value', $result);
$mockedBehavior = $this->getMock('Behavior', ['slugify']);
$this->Behaviors->set('Sluggable', $mockedBehavior);

$mockedBehavior
->expects($this->once())
->method('slugify')
->with(['some value'])
->will($this->returnValue('some-thing'));
$return = $this->Behaviors->call('slugify', [['some value']]);
$this->assertSame('some-thing', $return);
}

/**
Expand All @@ -195,16 +206,24 @@ public function testCallError() {
/**
* test call finder
*
* Setup a behavior, then replace it with a mock to verify methods are called.
* use dummy return values to verify the return value makes it back
*
* @return void
*/
public function testCallFinder() {
$this->Behaviors->load('Sluggable');
$result = $this->Behaviors->call('slugify', ['some value']);
$this->assertEquals('some_value', $result);
$mockedBehavior = $this->getMock('Behavior', ['findNoSlug']);
$this->Behaviors->set('Sluggable', $mockedBehavior);

$query = $this->getMock('Cake\ORM\Query', [], [null, null]);
$result = $this->Behaviors->callFinder('noSlug', [$query]);
$this->assertEquals($query, $result);
$mockedBehavior
->expects($this->once())
->method('findNoSlug')
->with($query, [])
->will($this->returnValue('example'));
$return = $this->Behaviors->callFinder('noSlug', [$query, []]);
$this->assertSame('example', $return);
}

/**
Expand Down

0 comments on commit 5aff237

Please sign in to comment.