PK AVYdL L LICENSEnu W+A The MIT License (MIT)
Copyright (c) 2013 Codeception PHP Testing Framework
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.
PK AVrYU VERSIONnu W+A 2.1.0PK AVL" .travis.ymlnu W+A language: php
php:
- 7.0
- 7.1
- 7.2
before_script:
- stty cols 160
- composer install -n --prefer-source
script: "php vendor/bin/codecept run"
PK AVou7! ! codeception.ymlnu W+A paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
coverage:
enabled: true
include:
- src/*PK AV$) RoboFile.phpnu W+A 'AspectMock\Test',
'docs/ClassProxy.md' => 'AspectMock\Proxy\ClassProxy',
'docs/InstanceProxy.md' => 'AspectMock\Proxy\InstanceProxy',
'docs/FuncProxy.md' => 'AspectMock\Proxy\FuncProxy'
];
protected function version()
{
return file_get_contents(__DIR__.'/VERSION');
}
public function release()
{
$this->say("Releasing AspectMock");
$this->test();
$this->docs();
$this->taskGitStack()
->add('CHANGELOG.md')
->commit('updated')
->push()
->run();
$this->taskGitStack()
->tag($this->version())
->push(' --tags')
->run();
$this->bump();
}
public function docs()
{
foreach ($this->docs as $file => $class) {
class_exists($class, true);
$this->taskGenDoc($file)
->docClass($class)
->filterMethods(function(\ReflectionMethod $method) {
if ($method->isConstructor() or $method->isDestructor()) return false;
if (!$method->isPublic()) return false;
if (strpos($method->name, '_') === 0) return false;
return true;
})
->processMethodDocBlock(
function (\ReflectionMethod $m, $doc) {
$doc = str_replace(array('@since'), array(' * available since version'), $doc);
$doc = str_replace(array(' @', "\n@"), array(" * ", "\n * "), $doc);
return $doc;
})
->processProperty(false)
->run();
}
}
public function changed($addition)
{
$this->taskChangelog()
->version($this->version())
->change($addition)
->run();
}
public function bump($version = null)
{
if (!$version) {
$versionParts = explode('.', $this->version());
$versionParts[count($versionParts)-1]++;
$version = implode('.', $versionParts);
}
file_put_contents('VERSION', $version);
}
public function test()
{
$res = $this->taskCodecept()->run();
if (!$res) {
$this->say('Tests did not pass, release declined');
exit;
}
}
}
PK AV)} }
composer.jsonnu W+A {
"name": "codeception/aspect-mock",
"description": "Experimental Mocking Framework powered by Aspects",
"authors": [
{
"name": "Michael Bodnarchuk",
"email": "davert@codeception.com"
}
],
"autoload": {
"psr-0": {
"AspectMock": "src/"
}
},
"require": {
"php": ">=5.6.0",
"goaop/framework": "^2.2.0",
"symfony/finder": "~2.4|~3.0|~4.0"
},
"require-dev": {
"codeception/base": "^2.4",
"codeception/verify": "~0.2",
"codeception/specify": "~0.3"
},
"license": "MIT"
}
PK AV%_ CHANGELOG.mdnu W+A # Changelog
#### 2.1.0
* Add missing type hints and parameter types to FuncProxy. See #135 by @SenseException
* Added support for optional and referenced parameters in built-in functions. See #133 by @bhoehl
* Fixed `return void` issue #123 by @zuozp8. See #130
#### 2.0.0
* **Updated to Go AOP Framework 2.0**
* PHP7 (with typehints) supported
* Minimal PHP version is PHP 5.6
#### 1.0.0
* **Updated to Go AOP Framework 1.0**
* Added verifying inherited method calls by @torreytsui. See #90
* Replaces `return` with `yield` for non-root namespaces. By @faridanthony See #93
* Fix bug that class does not bind in static double by @torreytsui. See #89
#### 0.5.5
* compatible with Symfony3 and PHP7
#### 0.5.4
* Improved namespace handling
* Added ability to display actually passed parameter in the error message
* Fixed counting of dynamic class methods (#24)
* Fixes for functions that have a brace as default on parametersi
* Replace return with yield when docComments returns Generator
#### 0.5.3
* Updated to goaop/framework 0.6.x and codeception 2.1
#### 0.5.1
* Fixed strict errors for func verifier
#### 0.5.0
* `test::ns` method removed
* Mocking functions implemented with `test::func` method
* Fixed mocking functions with arguments passed by reference (#34)
* Fixed passing arguments by reference in InstanceProxy
* Debug mode can be disabled in options with `debug => false`
* Updated to Go\Aop 0.5.0
#### 0.5.0-beta 05/14/2014
* Moved to Go\Aop 0.5.x-dev
#### 0.4.2 05/09/2014
* Depdendency on AspectMock ~0.4.0
#### 0.4.1
* RoboFile
* Verify invocation arguments with closures
* Verify invocation arguments with closures
* Vetter support for traits
PK AVv tests/unit.suite.ymlnu W+A # Codeception Test Suite Configuration
# suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy
modules:
enabled: [CodeHelper]
PK AVU " tests/_data/demo/TraitedClass2.phpnu W+A
* Move forward to next element
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
*/
public function next()
{
// TODO: Implement next() method.
}
/**
* (PHP 5 >= 5.0.0)
* Return the key of the current element
* @link http://php.net/manual/en/iterator.key.php
* @return mixed scalar on success, or null on failure.
*/
public function key()
{
// TODO: Implement key() method.
}
/**
* (PHP 5 >= 5.0.0)
* Checks if current position is valid
* @link http://php.net/manual/en/iterator.valid.php
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
public function valid()
{
// TODO: Implement valid() method.
}
/**
* (PHP 5 >= 5.0.0)
* Rewind the Iterator to the first element
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
*/
public function rewind()
{
// TODO: Implement rewind() method.
}
}PK AVI tests/_data/demo/UserModel.phpnu W+A $value)
{
$this->$key = $value;
}
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setNameAndInfo($name, $info)
{
$this->name = $name;
$this->info = $info;
return $this;
}
/**
* @return mixed
*/
public function getNameAndInfo()
{
return array($this->name, $this->info);
}
/**
* @param array $info
*/
public function setInfo($info)
{
$this->info = $info;
return $this;
}
/**
* @return array
*/
public function getInfo($info)
{
return $this->info;
}
function save()
{
throw new \PHPUnit_Framework_AssertionFailedError("I should not be called");
}
public function __call($name, $args = array())
{
if ($name == 'renameUser') return 'David Blane';
}
public static function __callStatic($name, $args)
{
if ($name == 'defaultRole') return "member";
}
public function dump()
{
return file_put_contents(\Codeception\Configuration::logDir().'user.txt',$this->name);
}
}PK AVَ # tests/_data/demo/AdminUserModel.phpnu W+A name = "Admin_111";
parent::save();
}
}PK AV J J " tests/_data/demo/TraitedClass1.phpnu W+A save();
}
public function updateName(UserModel $user)
{
$user->setName("Current User");
$user->save();
}
public function renameUser(UserModel $user, $name)
{
$user->renameUser($name);
$user->save();
}
public static function renameStatic(UserModel $user, $name)
{
$user->renameUser($name);
$user->save();
}
public function __call($name, $args)
{
if ($name == 'rename') {
return 'David Blane';
}
}
}
PK AVy y ! tests/_data/demo/WorkingTrait.phpnu W+A add('AspectMock', __DIR__ . '/../../src');
$loader->add('demo', __DIR__ );
$loader->register();
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'debug' => true,
'cacheDir' => __DIR__.'/cache',
]);
$user = new demo\UserModel;
$user->save();PK AVhf9 tests/_data/php7.phpnu W+A add('demo',__DIR__);
//$loader->register();
require_once __DIR__.'/demo/UserModel.php';
require_once __DIR__.'/demo/UserService.php';
require_once __DIR__.'/demo/AdminUserModel.php';
require_once __DIR__.'/demo/WorkingTrait.php';PK AVY{|h h tests/_bootstrap.phpnu W+A add('AspectMock', __DIR__ . '/../src');
$loader->add('demo', __DIR__ . '/_data');
$loader->register();
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'cacheDir' => __DIR__.'/_data/cache',
'includePaths' => [__DIR__.'/_data/demo'],
'interceptFunctions' => true
]);PK AV-Q
tests/unit/MockFailedTest.phpnu W+A expectException('PHPUnit_Framework_ExpectationFailedException');
}
protected function tearDown()
{
double::clean();
}
protected function user()
{
$user = new UserModel();
double::registerObject($user);
$user = new InstanceProxy($user);
return $user;
}
protected function userProxy()
{
$userProxy = new ClassProxy('demo\UserModel');
double::registerClass('demo\UserModel');
return $userProxy;
}
public function testInstanceInvoked()
{
$this->user()->verifyInvoked('setName');
}
public function testInstanceInvokedWothoutParams()
{
$user = $this->user();
$user->setName('davert');
$user->verifyInvoked('setName',[]);
}
public function testInstanceInvokedMultipleTimes()
{
$user = $this->user();
$user->setName('davert');
$user->setName('jon');
$user->verifyInvokedMultipleTimes('setName',3);
}
public function testInstanceInvokedMultipleTimesWithoutParams()
{
$user = $this->user();
$user->setName('davert');
$user->setName('jon');
$user->verifyInvokedMultipleTimes('setName',2,['davert']);
}
public function testClassMethodFails()
{
$userProxy = $this->userProxy();
UserModel::tableName();
UserModel::tableName();
$userProxy->verifyInvokedOnce('tableName');
}
public function testClassMethodNeverInvokedFails()
{
$user = new UserModel();
$userProxy = $this->userProxy();
$user->setName('davert');
$userProxy->verifyNeverInvoked('setName');
}
public function testClassMethodInvokedMultipleTimes()
{
$user = new UserModel();
$userProxy = $this->userProxy();
$user->setName('davert');
$user->setName('bob');
$userProxy->verifyInvokedMultipleTimes('setName',2,['davert']);
}
public function testClassMethodInvoked()
{
$user = new UserModel();
$userProxy = $this->userProxy();
$user->setName(1111);
$userProxy->verifyInvoked('setName',[2222]);
}
public function testAnythingFail()
{
$anyProxy = new AnythingClassProxy('demo\UserModel');
$any = $anyProxy->construct();
$any->hello();
$anyProxy->verifyInvoked('hello');
}
}
PK AVz/> tests/unit/MockTest.phpnu W+A setName('davert');
$this->specify('setName() was invoked', function() use ($user) {
$user->verifyInvoked('setName');
$user->verifyInvoked('setName',['davert']);
$user->verifyInvokedMultipleTimes('setName',1);
$user->verifyInvokedMultipleTimes('setName',1,['davert']);
$user->verifyNeverInvoked('setName',['bugoga']);
});
$this->specify('save() was not invoked', function() use ($user) {
$user->verifyNeverInvoked('save');
$user->verifyNeverInvoked('save',['params']);
});
}
public function testVerifyClassMethods()
{
double::registerClass('demo\UserModel',['save' => null]);
$user = new ClassProxy('demo\UserModel');
$service = new UserService();
$service->create(array('name' => 'davert'));
$user->verifyInvoked('save');
$user->verifyInvoked('save',[]);
$user->verifyInvokedMultipleTimes('save',1);
$user->verifyNeverInvoked('getName');
}
public function testVerifyStaticMethods()
{
double::registerClass('demo\UserModel');
$user = new ClassProxy('demo\UserModel');
UserModel::tableName();
$user->verifyInvoked('tableName');
}
public function testVerifyThatWasCalledWithParameters()
{
$user = new UserModel();
double::registerObject($user);
$user = new InstanceProxy($user);
$user->setName('davert');
$user->setName('jon');
$user->verifyInvokedOnce('setName',['davert']);
}
public function testVerifyClassMethodCalled()
{
$user = new UserModel();
$userProxy = new ClassProxy('demo\UserModel');
double::registerClass('demo\UserModel');
$user->setName('davert');
$user->setName('jon');
$userProxy->verifyInvokedMultipleTimes('setName',2);
$userProxy->verifyInvokedOnce('setName',['jon']);
$userProxy->verifyNeverInvoked('save');
$userProxy->verifyNeverInvoked('setName',['bob']);
verify($user->getName())->equals('jon');
}
/**
* Allow verifying extended methods.
*
* Given:
*
*
*
*
*
* Verification:
*
*
* super();
*
* // Will pass
* $parentProxy->verifyInvoked('super');
* $childProxy->verifyInvoked('super');
* ?>
*
*/
public function testVerifyClassInheritedMethodCalled()
{
$adminUser = new AdminUserModel();
double::registerClass(\demo\UserModel::class);
double::registerClass(\demo\AdminUserModel::class);
$userProxy = new ClassProxy(\demo\UserModel::class);
$adminUserProxy = new ClassProxy(\demo\AdminUserModel::class);
$adminUser->getName();
$userProxy->verifyInvokedOnce('getName');
$adminUserProxy->verifyInvokedOnce('getName');
}
}PK AVɴw # tests/unit/FunctionInjectorTest.phpnu W+A funcInjector = new FunctionInjector('demo', 'strlen');
$this->funcOptionalParameterInjector = new FunctionInjector('demo', 'explode');
$this->funcReferencedParameterInjector = new FunctionInjector('demo', 'preg_match');
test::clean();
}
public function testTemplate()
{
$php = $this->funcInjector->getPHP();
verify($php)->contains("function strlen()");
verify($php)->contains("return call_user_func_array('strlen', func_get_args());");
}
public function testReferencedParameterTemplate()
{
$php = $this->funcReferencedParameterInjector->getPHP();
verify($php)->contains("function preg_match(\$p0, \$p1, &\$p2=NULL, \$p3=NULL, \$p4=NULL)");
verify($php)->contains("case 5: \$args = [\$p0, \$p1, &\$p2, \$p3, \$p4]; break;");
verify($php)->contains("case 4: \$args = [\$p0, \$p1, &\$p2, \$p3]; break;");
verify($php)->contains("case 3: \$args = [\$p0, \$p1, &\$p2]; break;");
verify($php)->contains("case 2: \$args = [\$p0, \$p1]; break;");
verify($php)->contains("case 1: \$args = [\$p0]; break;");
verify($php)->contains("return call_user_func_array('preg_match', \$args);");
}
public function testSave()
{
$this->funcInjector->save();
exec('php -l '.$this->funcInjector->getFileName(), $output, $code);
verify($code)->equals(0);
codecept_debug($this->funcInjector->getPHP());
}
public function testLoadFunc()
{
$this->funcInjector->save();
codecept_debug($this->funcInjector->getFileName());
$this->funcInjector->inject();
verify(strlen('hello'))->equals(5);
}
public function testReimplementFunc()
{
test::func('demo', 'strlen', 10);
verify(strlen('hello'))->equals(10);
}
public function testVerifier()
{
$func = test::func('demo', 'strlen', 10);
expect(strlen('hello'))->equals(10);
$func->verifyInvoked();
$func->verifyInvoked(['hello']);
$func->verifyInvokedOnce();
$func->verifyInvokedOnce(['hello']);
$func->verifyInvokedMultipleTimes(1, ['hello']);
$func->verifyNeverInvoked(['hee']);
}
public function testVerifierFullyQualifiedNamespace()
{
$func = test::func('\demo', 'strlen', 10);
expect(strlen('hello'))->equals(10);
$func->verifyInvoked();
$func->verifyInvoked(['hello']);
$func->verifyInvokedOnce();
$func->verifyInvokedOnce(['hello']);
$func->verifyInvokedMultipleTimes(1, ['hello']);
$func->verifyNeverInvoked(['hee']);
}
/**
* @test
* @expectedException PHPUnit_Framework_ExpectationFailedException
*/
public function testFailedVerification()
{
$func = test::func('demo', 'strlen', function() { return 10; });
expect(strlen('hello'))->equals(10);
$func->verifyNeverInvoked();
}
public function testReferencedParameter()
{
$func = test::func('\demo', 'preg_match', 10);
expect(preg_match('@[0-9]+@', '1234', $match))->equals(10);
test::clean();
expect(preg_match('@[0-9]+@', '1234#', $match))->equals(1);
expect($match[0])->equals('1234');
}
}
PK AVxNB $ tests/unit/AccessDemoClassesTest.phpnu W+A 'davert']);
$this->assertEquals('davert', $user->getName());
}
/**
* @expectedException \PHPUnit\Framework\AssertionFailedError
*/
public function testUserService()
{
$service = new UserService();
$service->create(['name' => 'davert']);
}
}PK AVmu u tests/unit/_bootstrap.phpnu W+A isDefined())->true();
verify($class->hasMethod('setName'))->true();
verify($class->hasMethod('setNothing'))->false();
verify($class->hasProperty('name'))->true();
verify($class->hasProperty('otherName'))->false();
verify($class->traits())->isEmpty();
verify($class->interfaces())->isEmpty();
verify($class->parent())->null();
}
public function testMegaClassValidations()
{
$class = test::double('demo\MegaClass');
/** @var $class ClassProxy **/
verify($class->isDefined())->true();
verify($class->hasMethod('setName'))->false();
verify($class->traits())->contains('Codeception\Specify');
verify($class->interfaces())->contains('Iterator');
verify($class->parent())->equals('stdClass');
}
public function testUndefinedClass()
{
$this->setExpectedException('Exception');
test::double('MyUndefinedClass');
}
public function testInstanceCreation()
{
$this->class = test::double('demo\UserModel');
$this->specify('instance can be created from a class proxy', function() {
$user = $this->class->construct(['name' => 'davert']);
verify($user->getName())->equals('davert');
$this->assertInstanceOf('demo\UserModel', $user);
});
$this->specify('instance can be created without constructor', function() {
$user = $this->class->make();
$this->assertInstanceOf('demo\UserModel', $user);
});
}
public function testClassWithTraits() {
// if a trait is used by more than one doubled class, when BeforeMockTransformer
// runs on the second class it will see the trait's methods as being a part of
// the class itself, and try to inject its code into the class, rather than the
// trait. in failure mode, this test will result in:
// Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)
// in [...]/TraitedModel2.php
$unused = test::double('demo\TraitedClass1'); // this model uses `TraitedModelTrait`
$class = test::double('demo\TraitedClass2'); // so does this one
/** @var $class ClassProxy **/
verify($class->isDefined())->true();
verify($class->hasMethod('method1InTrait'))->true();
verify($class->hasMethod('methodInClass'))->true();
}
}
PK AV