diff --git a/src/Soap.php b/src/Soap.php index 80a2878..c6cf45c 100644 --- a/src/Soap.php +++ b/src/Soap.php @@ -3,6 +3,7 @@ namespace RicorocksDigitalAgency\Soap; use Illuminate\Support\Traits\ForwardsCalls; +use Illuminate\Support\Traits\Macroable; use RicorocksDigitalAgency\Soap\Parameters\Node; use RicorocksDigitalAgency\Soap\Request\Request; use RicorocksDigitalAgency\Soap\Support\Fakery\Fakery; @@ -10,6 +11,9 @@ class Soap { use ForwardsCalls; + use Macroable { + __call as __macroableCall; + } protected Fakery $fakery; protected $inclusions = []; @@ -67,6 +71,10 @@ public function afterRequesting(callable $hook) public function __call($method, $parameters) { + if (static::hasMacro($method)) { + return $this->__macroableCall($method, $parameters); + } + return $this->forwardCallTo($this->fakery, $method, $parameters); } } diff --git a/tests/MacroableTest.php b/tests/MacroableTest.php new file mode 100644 index 0000000..857c271 --- /dev/null +++ b/tests/MacroableTest.php @@ -0,0 +1,27 @@ +expectExceptionObject(new Exception("You sucessfully called this!")); + + Soap::macro('test', function() { + throw new Exception("You sucessfully called this!"); + }); + + Soap::test(); + + $this->fail("An exception should have been thrown!"); + } + +} \ No newline at end of file