-
Notifications
You must be signed in to change notification settings - Fork 28
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
46 changed files
with
3,076 additions
and
1,425 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
Thumbs.db | ||
ehthumbs.db | ||
Desktop.ini | ||
$RECYCLE.BIN/ | ||
.DS_Store | ||
.coverage | ||
.tox | ||
.idea/ | ||
vendor/ | ||
composer.lock | ||
/composer.lock | ||
/phpunit.xml | ||
website/ | ||
couscous-theme/ | ||
couscous.* |
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
{ | ||
"name": "Giuseppe Mazzapica", | ||
"email": "[email protected]", | ||
"homepage": "http://gm.zoomlab.it", | ||
"homepage": "https://gmazzap.me", | ||
"role": "Developer" | ||
} | ||
], | ||
|
@@ -27,21 +27,30 @@ | |
}, | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=5.4.0", | ||
"mockery/mockery": "*", | ||
"php": ">=5.6.0", | ||
"mockery/mockery": "1.*", | ||
"antecedent/patchwork": "2.0.*" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.8", | ||
"mockery/mockery": "0.9.3" | ||
"phpunit/phpunit": "~5.7.9" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Brain\\": "src/" | ||
} | ||
"Brain\\Monkey\\": "src/" | ||
}, | ||
"files": [ | ||
"vendor/antecedent/patchwork/Patchwork.php", | ||
"inc/api.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"files": [ "inc/wp-functions.php" ] | ||
"psr-4": { | ||
"Brain\\Monkey\\Tests\\": "tests/src/" | ||
}, | ||
"files": [ | ||
"inc/wp-helper-functions.php", | ||
"inc/wp-hook-functions.php" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
|
@@ -50,7 +59,8 @@ | |
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
"dev-master": "1.0.x-dev", | ||
"dev-version/2": "2.0.x-dev" | ||
} | ||
} | ||
} |
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,195 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
/* | ||
* This file is part of the BrainMonkey package. | ||
* | ||
* (c) Giuseppe Mazzapica | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Brain\Monkey { | ||
|
||
function setUp() | ||
{ | ||
require_once dirname(__DIR__).'/inc/wp-hook-functions.php'; | ||
require_once dirname(__DIR__).'/inc/wp-helper-functions.php'; | ||
} | ||
|
||
function tearDown() | ||
{ | ||
Container::instance()->reset(); | ||
\Mockery::close(); | ||
\Patchwork\restoreAll(); | ||
} | ||
} | ||
|
||
namespace Brain\Monkey\Functions { | ||
|
||
use Brain\Monkey\Container; | ||
use Brain\Monkey\Expectation\FunctionStubFactory; | ||
use Brain\Monkey\Names\FunctionName; | ||
|
||
/** | ||
* Factory method: receives the name of the function to mock and returns an instance of | ||
* FunctionStub. | ||
* | ||
* @param string $function_name the name of the function to mock | ||
* @return \Brain\Monkey\Expectation\FunctionStub | ||
*/ | ||
function when($function_name) | ||
{ | ||
return Container::instance() | ||
->functionStubFactory() | ||
->create(new FunctionName($function_name), FunctionStubFactory::SCOPE_STUB); | ||
} | ||
|
||
/** | ||
* Returns a Mockery Expectation object, where is possible to set all the expectations, using | ||
* Mockery methods. | ||
* | ||
* @param string $function_name | ||
* @return \Brain\Monkey\Expectation\Expectation | ||
*/ | ||
function expect($function_name) | ||
{ | ||
$name = new FunctionName($function_name); | ||
$expectation = Container::instance() | ||
->expectationFactory() | ||
->forFunctionExecuted($function_name); | ||
|
||
$factory = Container::instance()->functionStubFactory(); | ||
if ( ! $factory->has($name)) { | ||
$factory->create($name, FunctionStubFactory::SCOPE_EXPECTATION) | ||
->replaceUsingExpectation($expectation); | ||
|
||
} | ||
|
||
return $expectation; | ||
} | ||
} | ||
|
||
namespace Brain\Monkey\Actions { | ||
|
||
use Brain\Monkey\Container; | ||
use Brain\Monkey\Hooks; | ||
|
||
/** | ||
* @param string $action | ||
* @return \Brain\Monkey\Expectation\Expectation | ||
*/ | ||
function expectAdded($action) | ||
{ | ||
return Container::instance() | ||
->expectationFactory() | ||
->forActionAdded($action); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @return \Brain\Monkey\Expectation\Expectation | ||
*/ | ||
function expectDone($action) | ||
{ | ||
return Container::instance() | ||
->expectationFactory() | ||
->forActionDone($action); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @param null $callback | ||
* @return bool | ||
*/ | ||
function has($action, $callback = null) | ||
{ | ||
return Container::instance() | ||
->hookStorage() | ||
->isHookAdded(Hooks\HookStorage::ACTIONS, $action, $callback); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @return int | ||
*/ | ||
function did($action) | ||
{ | ||
return Container::instance() | ||
->hookStorage() | ||
->isHookDone(Hooks\HookStorage::ACTIONS, $action); | ||
} | ||
|
||
/** | ||
* @param string $action | ||
* @return bool | ||
*/ | ||
function doing($action) | ||
{ | ||
return Container::instance() | ||
->hookRunningStack() | ||
->has($action); | ||
} | ||
} | ||
|
||
namespace Brain\Monkey\Filters { | ||
|
||
use Brain\Monkey\Container; | ||
use Brain\Monkey\Hooks; | ||
|
||
/** | ||
* @param string $filter | ||
* @return \Brain\Monkey\Expectation\Expectation | ||
*/ | ||
function expectAdded($filter) | ||
{ | ||
return Container::instance() | ||
->expectationFactory() | ||
->forFilterAdded($filter); | ||
} | ||
|
||
/** | ||
* @param string $filter | ||
* @return \Brain\Monkey\Expectation\Expectation | ||
*/ | ||
function expectApplied($filter) | ||
{ | ||
return Container::instance() | ||
->expectationFactory() | ||
->forFilterApplied($filter); | ||
} | ||
|
||
/** | ||
* @param string $filter | ||
* @param null $callback | ||
* @return bool | ||
*/ | ||
function has($filter, $callback = null) | ||
{ | ||
return Container::instance() | ||
->hookStorage() | ||
->isHookAdded(Hooks\HookStorage::FILTERS, $filter, $callback); | ||
} | ||
|
||
/** | ||
* @param string $filter | ||
* @return int | ||
*/ | ||
function applied($filter) | ||
{ | ||
return Container::instance() | ||
->hookStorage() | ||
->isHookDone(Hooks\HookStorage::FILTERS, $filter); | ||
} | ||
|
||
/** | ||
* @param string $filter | ||
* @return bool | ||
*/ | ||
function doing($filter) | ||
{ | ||
return Container::instance() | ||
->hookRunningStack() | ||
->has($filter); | ||
} | ||
} | ||
|
Oops, something went wrong.