-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from PrisisForks/master
add files back
- Loading branch information
Showing
8 changed files
with
204 additions
and
11 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
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,7 @@ | ||
<?php | ||
namespace Gwa\Wordpress\MockeryWpBridge\Contracts; | ||
|
||
interface WpBridgeInterface | ||
{ | ||
public function __call($function, $args); | ||
} |
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,105 @@ | ||
<?php | ||
namespace Gwa\Wordpress\MockeryWpBridge; | ||
|
||
use Gwa\Wordpress\MockeryWpBridge\Contracts\WpBridgeInterface; | ||
use Mockery; | ||
|
||
class MockeryWpBridge implements WpBridgeInterface | ||
{ | ||
/** | ||
* Mockery instance. | ||
* | ||
* @var \Mockery | ||
*/ | ||
private $mock; | ||
|
||
/** | ||
* All shortcodes | ||
* | ||
* @var array | ||
*/ | ||
private $shortcodes = []; | ||
|
||
/* -------- */ | ||
|
||
/** | ||
* Add a shortcode. | ||
* | ||
* @param string $tag | ||
* | ||
* @param mixed $func | ||
*/ | ||
public function addShortcode($tag, $func) | ||
{ | ||
$this->shortcodes[$tag] = $func; | ||
} | ||
|
||
/** | ||
* Check if shortcode exist. | ||
* | ||
* @param string $tag | ||
* | ||
* @return boolean | ||
*/ | ||
public function hasShortcode($tag) | ||
{ | ||
return isset($this->shortcodes[$tag]); | ||
} | ||
|
||
/** | ||
* Get a shortcode callback. | ||
* | ||
* @param string $tag | ||
* | ||
* @return mixed | ||
*/ | ||
public function getShortcodeCallback($tag) | ||
{ | ||
return isset($this->shortcodes[$tag]) ? $this->shortcodes[$tag] : null; | ||
} | ||
|
||
/** | ||
* Combines shortcode attributes with known attributes and fills in defaults when needed. | ||
* | ||
* @param array $pairs | ||
* @param array $atts | ||
* @param string|null $shortcode | ||
* | ||
* @return array | ||
*/ | ||
public function shortcodeAtts($pairs, $atts, $shortcode = null) | ||
{ | ||
return array_merge($pairs, $atts); | ||
} | ||
|
||
/* -------- */ | ||
|
||
/** | ||
* Wordpress mock on __() func. | ||
* | ||
* @param string $text | ||
* @param string $domain | ||
* | ||
* @return string | ||
*/ | ||
public function __($text, $domain) | ||
{ | ||
return $text; | ||
} | ||
|
||
/* -------- */ | ||
|
||
public function __call($function, $args) | ||
{ | ||
return call_user_func_array([$this->mock, $function], $args); | ||
} | ||
|
||
public function mock() | ||
{ | ||
if (!isset($this->mock)) { | ||
$this->mock = Mockery::mock('WpBridge'); | ||
} | ||
|
||
return $this->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,41 @@ | ||
<?php | ||
namespace Gwa\Wordpress\MockeryWpBridge\Traits; | ||
|
||
use Gwa\Wordpress\MockeryWpBridge\Contracts\WpBridgeInterface; | ||
|
||
/** | ||
* Trait to be used by all classes that use MockeryWpBridge | ||
*/ | ||
trait WpBridgeTrait | ||
{ | ||
/** | ||
* MockeryWpBridge instance. | ||
* | ||
* @var \Gwa\Wordpress\MockeryWpBridge\Contracts\WpBridgeInterface $wpbridge | ||
*/ | ||
private $wpbridge; | ||
|
||
/** | ||
* Set MockeryWpBridge. | ||
* | ||
* @param WpBridgeInterface $wpbridge | ||
* | ||
* @return WpBridgeTrait | ||
*/ | ||
public function setWpBridge(WpBridgeInterface $wpbridge) | ||
{ | ||
$this->wpbridge = $wpbridge; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get MockeryWpBridge. | ||
* | ||
* @return WpBridge | ||
*/ | ||
public function getWpBridge() | ||
{ | ||
return $this->wpbridge; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
namespace Gwa\Wordpress\MockeryWpBridge; | ||
|
||
use Gwa\Wordpress\MockeryWpBridge\Contracts\WpBridgeInterface; | ||
|
||
/** | ||
* Allows us to use a class to call methods in the global namespace. | ||
* Methods should be called in camelcase. | ||
* | ||
* To call | ||
* wp_get_attachment_image_src(...); | ||
* use | ||
* $bridge->wpGetAttachmentImageSrc(...); | ||
*/ | ||
class WpBridge implements WpBridgeInterface | ||
{ | ||
/** | ||
* Magic call on all camel wordpress functions. | ||
* | ||
* @param string $function | ||
* | ||
* @return array | ||
*/ | ||
public function __call($function, $args) | ||
{ | ||
return call_user_func_array($this->camelToUnderscore($function), $args); | ||
} | ||
|
||
/** | ||
* Rename camelcase to underscore. | ||
* | ||
* @param string $string | ||
* | ||
* @return string | ||
*/ | ||
public function camelToUnderscore($string) | ||
{ | ||
return strtolower(preg_replace('/([a-z])([A-Z0-9])/', '$1_$2', $string)); | ||
} | ||
} |
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