ObjectWrapperOnUserTest.php 4.19 KB
Newer Older
llaffont's avatar
llaffont committed
1
<?php 
llaffont's avatar
llaffont committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
STORM is under the MIT License (MIT)

Copyright (c) 2010-2011 Agence Française Informatique http://www.afi-sa.fr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

27
class Storm_Test_ObjectWrapperOnUserTest extends PHPUnit\Framework\TestCase {
Laurent's avatar
Laurent committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
  public function setUp() {
    $this->user = new Storm_Test_Mock_User();
    $this->user
      ->setName('James Bond')
      ->setLicence('007');
    $this->user_wrapper = Storm_Test_ObjectWrapper
      ::on($this->user)
      ->setGoal('Kill GoldenEye')
      ->setLocation('Shangai');
  }
  
    
  /** @test */
  public function callOnWrapperGetNameShouldCallUserGetName() {
    $this->assertEquals('James Bond', $this->user_wrapper->getName());
  }
llaffont's avatar
llaffont committed
44 45


Laurent's avatar
Laurent committed
46 47 48 49
  /** @test */
  function getWrappedObjectShouldReturnJames() {
    $this->assertEquals($this->user, $this->user_wrapper->getWrappedObject());
  }
50 51


Laurent's avatar
Laurent committed
52 53 54 55
  /** @test */
  public function callOnWrapperGetLicenceShouldCallUserGetLicence() {
    $this->assertEquals('007', $this->user_wrapper->getLicence());
  }
llaffont's avatar
llaffont committed
56 57


Laurent's avatar
Laurent committed
58 59 60 61
  /** @test */
  public function zorkShouldNotHaveBeenCalled() {
    $this->assertFalse($this->user_wrapper->methodHasBeenCalled('zork'));
  }
llaffont's avatar
llaffont committed
62 63


Laurent's avatar
Laurent committed
64 65 66 67 68
  /** @test */
  public function setLocationParisShouldNotHaveBeenCalled() {
    $this->assertFalse($this->user_wrapper->methodHasBeenCalledWithParams('setLocation', 
                                                                          array('Paris')));
  }
69 70


Laurent's avatar
Laurent committed
71 72 73 74 75
  /** @test */
  public function setLocationShangaiShouldNotHaveBeenCalled() {
    $this->assertTrue($this->user_wrapper->methodHasBeenCalledWithParams('setLocation', 
                                                                         array('Shangai')));
  }
76 77


Laurent's avatar
Laurent committed
78 79 80 81
  /** @test */
  public function setLocationShouldHaveBeenCalled() {
    $this->assertTrue($this->user_wrapper->methodHasBeenCalled('setLocation'));
  }
llaffont's avatar
llaffont committed
82 83


Laurent's avatar
Laurent committed
84 85 86 87 88
  /** @test */
  public function setLocationParamsShouldContainShangai() {
    $this->assertEquals(array('Shangai'), 
                        $this->user_wrapper->getAttributesForLastCallOn('setLocation'));
  }
llaffont's avatar
llaffont committed
89 90


Laurent's avatar
Laurent committed
91 92 93 94
  /** @test */
  public function callSetGoalOnWrapperShouldCallSetGoalOnUser() {
    $this->assertEquals('Kill GoldenEye', $this->user->getGoal());
  }
llaffont's avatar
llaffont committed
95 96


Laurent's avatar
Laurent committed
97 98 99 100 101 102
  /** @test */
  public function setGoalParamsShouldContainKillGoldenEye() {
    $this->assertEquals(array('Kill GoldenEye'), 
                        $this->user_wrapper->getAttributesForLastCallOn('setGoal'));
  }
  
llaffont's avatar
llaffont committed
103

Laurent's avatar
Laurent committed
104 105 106 107
  /** @test  */
  public function setGoalShouldHaveBeenCalled() {
    $this->assertTrue($this->user_wrapper->methodHasBeenCalled('setGoal')); 
  } 
llaffont's avatar
llaffont committed
108 109


Laurent's avatar
Laurent committed
110 111 112 113 114
  /** @test */
  public function setExpectationOnGetNameToReturnOSS117() {
    $this->user_wrapper->whenCalled('getName')->answers('OSS117');
    $this->assertEquals('OSS117', $this->user_wrapper->getName());  
  }
llaffont's avatar
llaffont committed
115 116


Laurent's avatar
Laurent committed
117 118 119 120 121
  /** @test */
  public function setExpectationOnGetLocationToReturnMiami() {
    $this->user_wrapper->whenCalled('getLocation')->answers('Miami');
    $this->assertEquals('Miami', $this->user_wrapper->getLocation()); 
  }
llaffont's avatar
llaffont committed
122 123


Laurent's avatar
Laurent committed
124 125 126 127 128 129
  /**
   * @expectedException Storm_Test_ObjectWrapperException
   * @expectedExceptionMessage Method 'zork' has never been called
   * @test
   */
  public function shouldRaiseExceptionWhenGettingAttributesForZork() {
llaffont's avatar
llaffont committed
130
    $this->user_wrapper->getAttributesForLastCallOn('zork');
Laurent's avatar
Laurent committed
131
  }
llaffont's avatar
llaffont committed
132 133
}
?>