|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / vendor / codeception / stub / src / Stub / |
Filename | /home/a/home/dev2.destoffenstraat.com/vendor/codeception/stub/src/Stub/Expected.php |
Size | 4.19 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 10-Aug-2019 18:20 |
Last accessed | 23-Aug-2025 05:01 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
namespace Codeception\Stub;
use PHPUnit\Framework\MockObject\Matcher\InvokedAtLeastOnce;
use PHPUnit\Framework\MockObject\Matcher\InvokedCount;
class Expected
{
/**
* Checks if a method never has been invoked
*
* If method invoked, it will immediately throw an
* exception.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make('User', [
* 'getName' => Expected::never(),
* 'someMethod' => function() {}
* ]);
* $user->someMethod();
* ?>
* ```
*
* @param mixed $params
* @return StubMarshaler
*/
public static function never($params = null)
{
return new StubMarshaler(
new InvokedCount(0),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked exactly one
* time.
*
* If the number is less or greater it will later be checked in verify() and also throw an
* exception.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::once('Davert'),
* 'someMethod' => function() {}
* )
* );
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::once(function() { return Faker::name(); });
* ```
*
* @param mixed $params
*
* @return StubMarshaler
*/
public static function once($params = null)
{
return new StubMarshaler(
new InvokedCount(1),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked at least one
* time.
*
* If the number of invocations is 0 it will throw an exception in verify.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::atLeastOnce('Davert')),
* 'someMethod' => function() {}
* )
* );
* $user->getName();
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
*
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::atLeastOnce(function() { return Faker::name(); });
* ```
*
* @param mixed $params
*
* @return StubMarshaler
*/
public static function atLeastOnce($params = null)
{
return new StubMarshaler(
new InvokedAtLeastOnce(),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked a certain amount
* of times.
* If the number of invocations exceeds the value it will immediately throw an
* exception,
* If the number is less it will later be checked in verify() and also throw an
* exception.
*
* ``` php
* <?php
* use \Codeception\Stub;
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::exactly(3, 'Davert'),
* 'someMethod' => function() {}
* )
* );
* $user->getName();
* $user->getName();
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::exactly(function() { return Faker::name() });
* ```
*
* @param int $count
* @param mixed $params
*
* @return StubMarshaler
*/
public static function exactly($count, $params = null)
{
return new StubMarshaler(
new InvokedCount($count),
self::closureIfNull($params)
);
}
private static function closureIfNull($params)
{
if ($params instanceof \Closure) {
return $params;
}
return function() use ($params) {
return $params;
};
}
}
namespace Codeception\Stub;
use PHPUnit\Framework\MockObject\Matcher\InvokedAtLeastOnce;
use PHPUnit\Framework\MockObject\Matcher\InvokedCount;
class Expected
{
/**
* Checks if a method never has been invoked
*
* If method invoked, it will immediately throw an
* exception.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make('User', [
* 'getName' => Expected::never(),
* 'someMethod' => function() {}
* ]);
* $user->someMethod();
* ?>
* ```
*
* @param mixed $params
* @return StubMarshaler
*/
public static function never($params = null)
{
return new StubMarshaler(
new InvokedCount(0),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked exactly one
* time.
*
* If the number is less or greater it will later be checked in verify() and also throw an
* exception.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::once('Davert'),
* 'someMethod' => function() {}
* )
* );
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::once(function() { return Faker::name(); });
* ```
*
* @param mixed $params
*
* @return StubMarshaler
*/
public static function once($params = null)
{
return new StubMarshaler(
new InvokedCount(1),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked at least one
* time.
*
* If the number of invocations is 0 it will throw an exception in verify.
*
* ```php
* <?php
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::atLeastOnce('Davert')),
* 'someMethod' => function() {}
* )
* );
* $user->getName();
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
*
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::atLeastOnce(function() { return Faker::name(); });
* ```
*
* @param mixed $params
*
* @return StubMarshaler
*/
public static function atLeastOnce($params = null)
{
return new StubMarshaler(
new InvokedAtLeastOnce(),
self::closureIfNull($params)
);
}
/**
* Checks if a method has been invoked a certain amount
* of times.
* If the number of invocations exceeds the value it will immediately throw an
* exception,
* If the number is less it will later be checked in verify() and also throw an
* exception.
*
* ``` php
* <?php
* use \Codeception\Stub;
* use \Codeception\Stub\Expected;
*
* $user = $this->make(
* 'User',
* array(
* 'getName' => Expected::exactly(3, 'Davert'),
* 'someMethod' => function() {}
* )
* );
* $user->getName();
* $user->getName();
* $userName = $user->getName();
* $this->assertEquals('Davert', $userName);
* ?>
* ```
* Alternatively, a function can be passed as parameter:
*
* ```php
* <?php
* Expected::exactly(function() { return Faker::name() });
* ```
*
* @param int $count
* @param mixed $params
*
* @return StubMarshaler
*/
public static function exactly($count, $params = null)
{
return new StubMarshaler(
new InvokedCount($count),
self::closureIfNull($params)
);
}
private static function closureIfNull($params)
{
if ($params instanceof \Closure) {
return $params;
}
return function() use ($params) {
return $params;
};
}
}