Skip to content

Commit

Permalink
presunuti vyjimek
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-hajek committed Aug 11, 2015
1 parent a596dbd commit 4186e24
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 66 deletions.
27 changes: 20 additions & 7 deletions src/Mocker/Builder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php
namespace Jelito\DevStack\Mocker;
use Jelito\DevStack\Mocker\Exception;
use Jelito\DevStack\Mocker\Exception\FinalMethodException;
use Jelito\DevStack\Mocker\Exception\NonExistentMethodException;
use Jelito\DevStack\Mocker\Exception\PrivateMethodException;
use Jelito\DevStack\Mocker\Exception\ProtectedMethodException;
use Jelito\DevStack\Mocker\Exception\StaticMethodException;
use Jelito\DevStack\Mocker\Exception\UndeclaredMethodInvocationException;
use Jelito\DevStack\Mocker\Exception\UnknownVerifyMethodException;

/**
* @internal
Expand Down Expand Up @@ -94,16 +102,17 @@ public function getVerifyMethod($name)

/**
* @param string $name
* @throws FinalMethodException
* @throws NonExistentMethodException
* @throws PrivateMethodException
* @throws NonExistentMethodCallException
* @throws StaticMethodException
* @throws ProtectedMethodException
* @throws StaticMethodException
*/
private function checkOriginClassMethod($name)
{
$originMethods = $this->originClassMethods;
if (!array_key_exists($name, $originMethods)) {
throw new NonExistentMethodCallException($this->className . "::" . $name . ' does not exists.');
throw new NonExistentMethodException($this->className . "::" . $name . ' does not exists.');
}
$method = $originMethods[$name];
if ($method->isStatic()) {
Expand All @@ -115,6 +124,9 @@ private function checkOriginClassMethod($name)
if ($method->isProtected()) {
throw new ProtectedMethodException($this->className . "::" . $name . ' is protected, MockBuilder is useless. :(');
}
if ($method->isFinal()) {
throw new FinalMethodException($this->className . "::" . $name . ' is final, MockBuilder is useless. :(');
}
}

/**
Expand All @@ -128,18 +140,16 @@ public function createMock()

$this->mock = $this->testCase->getMock($this->className, $allMethodsNames, array(), '', false, false, false);
foreach ($methods as $methodName => $method) {
$returnParam = isset($this->returns[$methodName]) ? $this->returns[$methodName] : null;
$this->buildMethod($methodName, $returnParam);
$this->buildMethod($methodName);
}
$this->createUndeclaredMethods();
return $this->mock;
}

/**
* @param string $methodName
* @param mixed $returnParam
*/
private function buildMethod($methodName, $returnParam)
private function buildMethod($methodName)
{
$self = $this;

Expand Down Expand Up @@ -169,6 +179,9 @@ private function buildMethod($methodName, $returnParam)
$inputParams[] = count($self->getInvocations($methodName));
return call_user_func_array($returnValue, $inputParams);
break;
default:
throw new Exception("unknown method return type {$returnType}");
break;
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/Mocker/Exception.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Jelito\DevStack\Mocker;

class Exception extends \Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/FinalMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class FinalMethodException extends Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/NonExistentInvocationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class NonExistentInvocationException extends Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/NonExistentMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class NonExistentMethodException extends Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/PrivateMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class PrivateMethodException extends Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/ProtectedMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class ProtectedMethodException extends Exception
{
}
8 changes: 8 additions & 0 deletions src/Mocker/Exception/StaticMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class StaticMethodException extends Exception
{
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace Jelito\DevStack\Mocker;
namespace Jelito\DevStack\Mocker\Exception;

class UndeclaredMethodInvocationException extends \Exception
{
Expand Down
8 changes: 8 additions & 0 deletions src/Mocker/Exception/UnknownVerifyMethodException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker\Exception;

use Jelito\DevStack\Mocker\Exception;

class UnknownVerifyMethodException extends Exception
{
}
6 changes: 0 additions & 6 deletions src/Mocker/NonExistentInvocationException.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Mocker/NonExistentMethodCallException.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Mocker/PrivateMethodException.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Mocker/ProtectedMethodException.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Mocker/StaticMethodException.php

This file was deleted.

6 changes: 0 additions & 6 deletions src/Mocker/UnknownVerifyMethodException.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Mocker/VerifyMethod.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Jelito\DevStack\Mocker;

use Jelito\DevStack\Mocker\Exception\NonExistentInvocationException;

class VerifyMethod
{
/**
Expand Down
6 changes: 6 additions & 0 deletions tests/src/mocker/MockBuilderTestClass.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

class MockBuilderTestClass
{
public $publicProperty;
Expand Down Expand Up @@ -27,4 +28,9 @@ public static function staticMethod($a = null, $b = null)
{
return $a + $b;
}

final public function finalMethod($a = null, $b = null)
{
return $a + $b;
}
}
Loading

0 comments on commit 4186e24

Please sign in to comment.