Giter VIP home page Giter VIP logo

Comments (6)

jails avatar jails commented on May 12, 2024

Afaik,

Stub::on("my\name\space\Client")->method('save')->andReturn(true, false);

Should work out of the box.

from kahlan.

m1ome avatar m1ome commented on May 12, 2024

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.

jails avatar jails commented on May 12, 2024

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.

m1ome avatar m1ome commented on May 12, 2024

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.

jails avatar jails commented on May 12, 2024

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.

m1ome avatar m1ome commented on May 12, 2024

Thank for a help!

from kahlan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.