Skip to content

Instantly share code, notes, and snippets.

def hello()
return x+y
@ahmed-abid
ahmed-abid / testNoDependencyInjectionNeeded.php
Created March 29, 2018 10:40
test No Dependency Injection Needed
<?php
/** no dependency injection example */
public function testNoDependencyInjectionNeeded(){
$object = new NoDependencyInjectionNeeded();
$original = $object->getName();
$this->assertEquals('users — No Dependency Injection Needed', $original);
Moke::double('App\AspectMock\UserModel', ['tableName' => 'my_users']);
$mokedName = $object->getName();
@ahmed-abid
ahmed-abid / testTableName.php
Last active March 29, 2018 10:32
simple mock example
<?php
/** simple mock example */
public function testTableName()
{
$tableName = UserModel::tableName();
$this->assertEquals('users', $tableName);
$userModel = Moke::double('App\AspectMock\UserModel', ['tableName' => 'my_users']);
$name = UserModel::tableName();
$this->assertEquals('my_users', $name);
@ahmed-abid
ahmed-abid / UserModel.php
Created March 29, 2018 09:54
simple aspect mock example
<?php
class UserModel
{
public static function tableName()
{
return 'users';
}
public static function someMethod($arg1, $arg2)
{
return $arg1 . ' '. $arg2;
@ahmed-abid
ahmed-abid / time.php
Last active April 4, 2018 06:45
aspectmock time example
<?php
namespace App\Core\Test;
/**
* My Class : example to show the case of Standard PHP functions
*
* Class User
*
* @package App\Core\Test
@ahmed-abid
ahmed-abid / UserModel.php
Last active April 4, 2018 06:46
aspect mock article
<?php
namespace App\Core\Test;
/**
* User Model : example to show the use of static methos
*
* Class UserModel
*
* @package App\Core\Test
@ahmed-abid
ahmed-abid / NoDependencyInjectionNeeded.php
Last active April 4, 2018 06:46
No Dependency Injection Needed
<?php
namespace App\Core\Test;
use UserModel;
/**
* My Class : example to show the case of no dependency injection
*
* Class MyClass
@ahmed-abid
ahmed-abid / _bootstrap.php
Last active January 28, 2018 14:17
PHP code is now 99% testable with AspectMock
<?php
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
'appDir' => _DIR_ . '/..',
'debug' => true,
'includePaths' => [
_DIR_ . '/../vendor/laravel',
_DIR_ . '/../app'
],
@ahmed-abid
ahmed-abid / AspectMockTest.php
Created January 28, 2018 14:07
PHP code is now 99% testable with AspectMock
<?php
namespace tests\AspectMock;
use Codeception\TestCase\Test;
use App\AspectMock\UserModel;
use App\AspectMock\NoDependencyInjectionNeeded;
use App\AspectMock\User2;
use AspectMock\Test as Moke;
class AspectMockTest extends Test
{