Skip to content

Instantly share code, notes, and snippets.

@ahmed-abid
Created January 28, 2018 14:12
Show Gist options
  • Save ahmed-abid/ca11da1c836518e1f898de400b06f30d to your computer and use it in GitHub Desktop.
Save ahmed-abid/ca11da1c836518e1f898de400b06f30d to your computer and use it in GitHub Desktop.
PHP code is now 99% testable with AspectMock
<?php
namespace App\AspectMock;
class ActiveRecord
{
public function save($name)
{
return 'saved ActiveRecord success' . $name;
}
}
class UserModel
{
public static function tableName()
{
return 'users';
}
public static function someMethod($arg1, $arg2)
{
return $arg1 . ' '. $arg2;
}
}
class NoDependencyInjectionNeeded
{
public function getName()
{
$user = new UserModel();
$name = $user->tableName();
return $name . ' — No Dependency Injection Needed';
}
}
class User2 extends ActiveRecord
{
public $name = 'user2 name';
public function __construct($name)
{
$this->name = $name;
}
public function getTime()
{
return time();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment