Comments (6)
Afaik,
Stub::on("my\name\space\Client")->method('save')->andReturn(true, false);
Should work out of the box.
from kahlan.
No, it's not a right way. It will not be saved correcly and if should work in id something like $client->id
in a code it would not be possible. The right way is:
- On the first run call normal
save
- On the second run call stubbed
save
Is it possible?
from kahlan.
Afaik you will need to manage the conditional aspect on your own.
Stub::on("my\name\space\Client")->method('save', function($data, $options) {
if (!$this->is_overaged) { // or some other condition
return parent::save($data, $options);
}
return false;
});
from kahlan.
In my variant i have this:
fit("should throw on payment state change", function() {
Stub::on('Api\Models\Payment')->method('save', function($data = null, $whitelist = null) {
if ($this->status === 'manual') {
return false;
} else {
parent::save($data, $whitelist);
return true;
}
});
$this->request['timestamp'] = $this->request['timestamp'] + 1;
$this->request['money']['clear_amount'] = 1000;
$this->request['money']['balance_amount'] = 500;
$this->controller->setRequest($this->request);
expect(function() {
$this->controller->run('terminal');
})->toThrowLogic(ExceptionCodes::INTERNAL_ERROR);
});
And after run i have:
PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in /vagrant/crm/terminal/api/vendor/crysalead/kahlan/src/plugin/Call.php on line 79
from kahlan.
Your use case is a bit uncommon since it's a mix of an integration test (since you wan't the real save feature) & some unit test since you wan't to stub it too. And the fact that you are using Phalcon models makes it more difficult since you must have the layer patcher configured for Phalcon\Mvc\Model
. So since the inheritance is something like Stub->Layer->Model, you will need to call up the grand parent directly. So instead of parent::save($data, $whitelist);
using \Phalcon\Mvc\Model::save($data, $whitelist);
should solve this infinite loop issue.
from kahlan.
Thank for a help!
from kahlan.
Related Issues (20)
- Throw exception test failed with Pipeline CI/CD HOT 2
- How to mock ZipArchive behavior HOT 4
- Expect to throw a `TypeError` got failed, `actual: TypeError, expected: TypeError` HOT 4
- Error with PHP 8 HOT 1
- Unable to run the tests when `XDEBUG_MODE` have multiple values HOT 1
- Feature Request: Support focusing a specific test or suite with command line arguments
- php 8.1 support HOT 2
- PHP Fatal error: Type of Kahlan\PhpErrorException::$file must be string (as in class Exception) in... HOT 3
- toBeCalled within Class Static Methods HOT 1
- Breakpoint; debugging tests HOT 4
- Missing default value 0 for int properties with PHP8 attributes in single line HOT 1
- Unable to stub without overriding function HOT 5
- Process exit with code 1 in github action HOT 2
- stub / Modify constante HOT 1
- PHP 8.2: dynamic properties HOT 3
- PHP 8.2 Function utf8_decode() is deprecated HOT 1
- Support for never return type (PHP 8.1+) HOT 5
- Cannot exclude autoloaded files from monkey patching
- Multiple _T_ATTRIBUTE tokens in single line HOT 1
- Bug: toHaveLength() does not work with accented letters and multi-byte strings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kahlan.