Simplified PHPSpec + Wordpress approach
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
<?php | |
namespace MyApp | |
{ | |
class Foo | |
{ | |
public function interactWithWordpress() | |
{ | |
return get_option('my_option_name'); | |
} | |
} | |
} |
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
<?php | |
namespace spec\MyApp | |
{ | |
class FooSpec | |
{ | |
function it_shows() | |
{ | |
WordpressOptions::$options['my_option_name'] = 'bar'; | |
$this->interactWithWordpress()->shouldReturn('bar'); | |
} | |
} | |
class WordpressOptions | |
{ | |
public static $options = []; | |
} | |
} | |
namespace MyApp | |
{ | |
use spec\MyApp\WordpressOptions; | |
function get_option($optionName) | |
{ | |
return WordpressOptions::$options[$optionName]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment