Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since PHP cannot serialize anonymous functions. @see https://core.trac.wordpress.org/ticket/50482 @see sebastianbergmann/phpunit#2739
- Loading branch information
1 parent
d8edd0c
commit cdbcdee
Showing
7 changed files
with
179 additions
and
79 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
24 changes: 24 additions & 0 deletions
24
tests/testlibraries/ajax_invokers/class-ajax-fetch-invoker.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,24 @@ | ||
<?php | ||
/** | ||
* Ajax_Fetch_Invoker | ||
* | ||
* @package static_press\tests\testlibraries\ajax_invokers | ||
*/ | ||
|
||
namespace static_press\tests\testlibraries\ajax_invokers; | ||
|
||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/ajax_invokers/class-ajax-invoker.php'; | ||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/creators/class-mock-creator.php'; | ||
use static_press\tests\testlibraries\ajax_invokers\Ajax_Invoker; | ||
use static_press\tests\testlibraries\creators\Mock_Creator; | ||
/** | ||
* Class Ajax_Fetch_Invoker | ||
*/ | ||
class Ajax_Fetch_Invoker extends Ajax_Invoker { | ||
/** | ||
* Invokes ajax function. | ||
*/ | ||
protected function invoke_ajax() { | ||
$this->static_press->ajax_fetch( Mock_Creator::create_terminator_mock() ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/testlibraries/ajax_invokers/class-ajax-finalyze-invoker.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,24 @@ | ||
<?php | ||
/** | ||
* Ajax_Finalyze_Invoker | ||
* | ||
* @package static_press\tests\testlibraries\ajax_invokers | ||
*/ | ||
|
||
namespace static_press\tests\testlibraries\ajax_invokers; | ||
|
||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/ajax_invokers/class-ajax-invoker.php'; | ||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/creators/class-mock-creator.php'; | ||
use static_press\tests\testlibraries\ajax_invokers\Ajax_Invoker; | ||
use static_press\tests\testlibraries\creators\Mock_Creator; | ||
/** | ||
* Class Ajax_Finalyze_Invoker | ||
*/ | ||
class Ajax_Finalyze_Invoker extends Ajax_Invoker { | ||
/** | ||
* Invokes ajax function. | ||
*/ | ||
protected function invoke_ajax() { | ||
$this->static_press->ajax_finalyze( Mock_Creator::create_terminator_mock() ); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/testlibraries/ajax_invokers/class-ajax-init-invoker.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,24 @@ | ||
<?php | ||
/** | ||
* Ajax_Init_Invoker | ||
* | ||
* @package static_press\tests\testlibraries\ajax_invokers | ||
*/ | ||
|
||
namespace static_press\tests\testlibraries\ajax_invokers; | ||
|
||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/ajax_invokers/class-ajax-invoker.php'; | ||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/creators/class-mock-creator.php'; | ||
use static_press\tests\testlibraries\ajax_invokers\Ajax_Invoker; | ||
use static_press\tests\testlibraries\creators\Mock_Creator; | ||
/** | ||
* Class Ajax_Init_Invoker | ||
*/ | ||
class Ajax_Init_Invoker extends Ajax_Invoker { | ||
/** | ||
* Invokes ajax function. | ||
*/ | ||
protected function invoke_ajax() { | ||
$this->static_press->ajax_init( Mock_Creator::create_terminator_mock() ); | ||
} | ||
} |
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 | ||
/** | ||
* Ajax_Invoker | ||
* | ||
* @package static_press\tests\testlibraries\ajax_invokers | ||
*/ | ||
|
||
namespace static_press\tests\testlibraries\ajax_invokers; | ||
|
||
require_once STATIC_PRESS_PLUGIN_DIR . 'tests/testlibraries/exceptions/class-die-exception.php'; | ||
use static_press\tests\testlibraries\exceptions\Die_Exception; | ||
|
||
/** | ||
* Class Ajax_Invoker | ||
*/ | ||
abstract class Ajax_Invoker { | ||
/** | ||
* ExpectUrl constructor. | ||
* | ||
* @param PHPUnit_Framework_TestCase $test_case Expect type of URL object. | ||
* @param Static_Press $static_press StaticPress. | ||
*/ | ||
public function __construct( $test_case, $static_press ) { | ||
$this->test_case = $test_case; | ||
$this->static_press = $static_press; | ||
} | ||
|
||
/** | ||
* Requests. | ||
* | ||
* @return array JSON responce. | ||
*/ | ||
public function request() { | ||
ob_start(); | ||
try { | ||
$this->invoke_ajax(); | ||
} catch ( Die_Exception $exception ) { | ||
$output = ob_get_clean(); | ||
$this->test_case->assertEquals( 'Dead!', $exception->getMessage() ); | ||
return json_decode( $output, true ); | ||
} | ||
$this->test_case->fail(); | ||
} | ||
|
||
/** | ||
* Invokes ajax function. | ||
*/ | ||
abstract protected function invoke_ajax(); | ||
} |
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,34 @@ | ||
<?php | ||
/** | ||
* Class Error_Handler | ||
* | ||
* @package static_press\tests\testlibraries | ||
*/ | ||
|
||
namespace static_press\tests\testlibraries; | ||
|
||
/** | ||
* Error handler. | ||
*/ | ||
class Error_Handler { | ||
/** | ||
* Handles error. | ||
* | ||
* @param int $errno The first parameter, errno, contains the level of the error raised, as an integer. | ||
* @param string $errstr The second parameter, errstr, contains the error message, as a string. | ||
* @param string $errfile The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string. | ||
* @param int $errline The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer. | ||
* @param array $errcontext The fifth parameter is optional, errcontext, which is an array that points to the active symbol table at the point the error occurred. | ||
* In other words, errcontext will contain an array of every variable that existed in the scope the error was triggered in. | ||
* User error handler must not modify error context. | ||
* @return false | ||
* @throws \LogicException When error. | ||
*/ | ||
public function handle( $errno, $errstr, $errfile, $errline, $errcontext ) { | ||
// error was suppressed with the @-operator. | ||
if ( 0 === error_reporting() ) { | ||
return false; | ||
} | ||
throw new \LogicException( $errstr, $errno ); | ||
} | ||
} |
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