-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Mockery | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://github.com/padraic/mockery/blob/master/LICENSE | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to padraic@php.net so we can send you a copy immediately. | ||
* | ||
* @category Mockery | ||
* @package Mockery | ||
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com) | ||
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License | ||
*/ | ||
|
||
namespace Mockery; | ||
|
||
class ExpectsHigherOrderMessage extends HigherOrderMessage | ||
{ | ||
public function __construct(MockInterface $mock) | ||
{ | ||
return parent::__construct($mock, "shouldReceive"); | ||
} | ||
/** | ||
* @return Mockery\Expectation | ||
*/ | ||
public function __call($method, $args) | ||
{ | ||
$expectation = parent::__call($method, $args); | ||
|
||
return $expectation->once(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
library/Mockery/Generator/StringManipulation/Pass/AvoidMethodClashPass.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Mockery | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://github.com/padraic/mockery/blob/master/LICENSE | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to padraic@php.net so we can send you a copy immediately. | ||
* | ||
* @category Mockery | ||
* @package Mockery | ||
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com) | ||
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License | ||
*/ | ||
|
||
namespace Mockery\Generator\StringManipulation\Pass; | ||
|
||
use Mockery\Generator\Method; | ||
use Mockery\Generator\Parameter; | ||
use Mockery\Generator\MockConfiguration; | ||
|
||
class AvoidMethodClashPass implements Pass | ||
{ | ||
public function apply($code, MockConfiguration $config) | ||
{ | ||
$names = array_map(function ($method) { | ||
return $method->getName(); | ||
}, $config->getMethodsToMock()); | ||
|
||
foreach (["allows", "expects"] as $method) { | ||
if (in_array($method, $names)) { | ||
|
||
$code = preg_replace( | ||
"#// start method {$method}.*// end method {$method}#ms", | ||
"", | ||
$code | ||
); | ||
} | ||
|
||
} | ||
|
||
return $code; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Mockery | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://github.com/padraic/mockery/master/LICENSE | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to padraic@php.net so we can send you a copy immediately. | ||
* | ||
* @category Mockery | ||
* @package Mockery | ||
* @subpackage UnitTests | ||
* @copyright Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com) | ||
* @license http://github.com/padraic/mockery/blob/master/LICENSE New BSD License | ||
*/ | ||
|
||
namespace test\Mockery; | ||
|
||
use Mockery as m; | ||
use Mockery\Spy; | ||
use Mockery\Exception\InvalidCountException; | ||
|
||
class ClassWithAllowsMethod | ||
{ | ||
public function allows() | ||
{ | ||
return 123; | ||
} | ||
} | ||
|
||
class ClassWithExpectsMethod | ||
{ | ||
public function expects() | ||
{ | ||
return 123; | ||
} | ||
} | ||
|
||
class AllowsExpectsSyntaxTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @test */ | ||
public function allowsSetsUpMethodStub() | ||
{ | ||
$stub = m::mock(); | ||
$stub->allows()->foo(123)->andReturns(456); | ||
|
||
$this->assertEquals(456, $stub->foo(123)); | ||
} | ||
|
||
/** @test */ | ||
public function generateSkipsAllowsMethodIfAlreadyExists() | ||
{ | ||
$stub = m::mock("test\Mockery\ClassWithAllowsMethod"); | ||
|
||
$stub->shouldReceive('allows')->andReturn(123); | ||
|
||
$this->assertEquals(123, $stub->allows()); | ||
} | ||
|
||
/** @test */ | ||
public function expectsSetsUpExpectationOfOneCall() | ||
{ | ||
$mock = m::mock(); | ||
$mock->expects()->foo(123); | ||
|
||
$this->setExpectedException("Mockery\Exception\InvalidCountException"); | ||
m::close(); | ||
} | ||
|
||
/** @test */ | ||
public function generateSkipsExpectsMethodIfAlreadyExists() | ||
{ | ||
$stub = m::mock("test\Mockery\ClassWithExpectsMethod"); | ||
|
||
$stub->shouldReceive('expects')->andReturn(123); | ||
|
||
$this->assertEquals(123, $stub->expects()); | ||
} | ||
} |