Coder Social home page Coder Social logo

mockista's People

Contributors

bauer01 avatar fprochazka avatar janmarek avatar jasir avatar jiriknesl avatar jsifalda avatar khorsky avatar marten-cz avatar rikap avatar vysinsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mockista's Issues

Validace volaných parametrů.

Mám problém s tím, že když volám v testech mock s jinými parametry, než které definuji. Tak dostanu např. výjimku: "Mockista\MockException: Expected method Flame\Doctrine\EntityDao::findOneBy() should be called exactly once but not called at all." přitom volána byla jednou, pouze s jinými parametry.

Tohle je očekávané chování? Nebo je někde problém?

Předem děkuji za pomoc.

Support for PHP 7 scalar typehints?

Hello,
do you think it is possible to add support for PHP 7 scalar typehints?

Code sample:

<?php

class Repository
{

    /**
     * @param  int
     * @return int
     */
    public function getImagesCountByUrlId(int $urlId) : int
    {

    }

}

Mocking class above throws this error:

Fatal error: Declaration of Repository_1813543779::getImagesCountByUrlId($urlId) must be compatible with Repository::getImagesCountByUrlId(int $urlId): int in vendor/janmarek/mockista/Mockista/MockBuilder.php(49) : eval()'d code on line 22

CreateMock doesn't generate unique class name

When upgraded to PHP 5.4.21 (win), I started to getting this error:

Fatal error: Cannot redeclare class XY in ...\janmarek\mockista\Mockista\MockBuilder.php(41) : eval()'d code on line 220

When looking for the error source I found out that it's outside the Mockista - the problem is in the uniqid function. It could be generating same results when called quickly enough.

Does mockista check the existence of expected method?

I met a situation where I do suspect mockista of an error behavior. I've got something like this

interface IExample {
   public function x();
   public function y();
}

class Something {
   private $ex;

   function __construct(IExample ex) {
         $this->ex = $ex;
   }

   function something() {
         $this->ex->c();
   }
}
...
public function testSomething() {
   $mock = $this->mockista->create('XY\IExample');
   $mock->expects('c')
         ->once()
         ->andReturn(NULL);
   $this->sut->something();
   // and some assertion
}
...

I would expect mockista to tell me there is not such a method c in this mocked interface. Instead everything works as there is the method 'c', which is called in tested.

I met this during the refactoring session. I was refactoring the classes that implement the interface, changed the interface signature (removed that method) and come to this problem - I'm not capable to find out what classes do I need to change through test.

I could easily find it with IDE, but I guess this should be working too?

Is this a bug or did I make a mistake?

ProxyMock - mock that intercepts calls to existing object

This is feature we just working on. It is not final yet, but I would like to have your input.

Working name for this is ProxyMock.

Main idea is that sometimes you do not want your mock object to mock all calls for some object just intercepts some calls and let everything else pass to some real instance. Basically in test you only care about part of the object behaviour and do not want to be forced to set expects for all calls.

Most useful is this if mocked object has some complex behavior or computation or if call sequence and/or internal state is important for return values.

Creating of proxy mock is simple. Just pass existing instance instead of class/interface name when creating mock:

  class MyObject {
    public function multipleTwo($param) {
      return $param * 2;
    }
    public function plusOne($param) {
      return $param +1;
    }
  }

  $object = new MyObject();
  $mock = $mockista->create($object);

When we set no expects it will just passthrought all calls to original object:

  echo $mock->multipleTwo(10); // => 20
  echo $mock->plusOne(10); // => 11

We can set expect for some calls and return different values:

  $mock->expect('multipleTwo')->andReturn(100);
  echo $mock->multipleTwo(10); // => 100
  echo $mock->plusOne(10); // => 11

Of couse we can set expectations in number of calls as normal

  $mock->expect('multipleTwo')->once();
  echo $mock->multipleTwo(10); // => null
  $mock->assertExpectations();

For case when we want to set expectation but still return value computed by original object, new and* method will be added:

  $mock->expect('multipleTwo')->once()->andPassThrough();
  echo $mock->multipleTwo(10); // => 20
  $mock->assertExpectations();

Of course we can use some fake implementation of original object as well:

class MyDummyObject extends MyObject {
 ... some dummy behaviour
}

$mock = $mockista->create(new MyDummyObject());

So what do you think?

Declaration of __call() should be compatible with...

Zdravim,

mam jednoduchy mock:

$page = $this->mockista->create('\Harvester\Page\Page', array(
            'getUrl' => function() use($url) { return new Nette\Http\Url($url);},
        ));

a dostavam tento error:

Strict standards: Declaration of _Harvester_Page_Page_525bb7a224d22::__call() 
should be compatible with LeanMapper\Entity::__call($name, array $arguments) 
in /vendor/janmarek/mockista/Mockista/MockBuilder.php(41) : eval()'d code on line 148

pouzivam:

        "tharos/leanmapper": "dev-master",
        "janmarek/mockista": "dev-master",

Wrong expectations assert (maybe my misuse)

Hello,
I've started working with mockista and I've rewritten tests from codeception to nette/tester. In codeception I've used PhpUnit's getMock() method and tests were passing. When I use mockista it does not. Please see this test: https://github.com/annotatecms/packages/blob/nette-tester/tests/AnnotateCmsTests/Packages/PackageLoader.phpt#L215-L227. Do I use mockery in wrong way or is there a bug?


Edit: When I use jiriknesl/mockista it works and tests are passing. But I like the usage of your mockista more.

Wrong mock for class with getName() method

Hi,
I test create mock for Nette\Application\UI\Presenter I can't use method getName() because this method returns mock name instead of original value.

$presenterMock = $this->mockista->create('Nette\Application\UI\Presenter');
$presenterMock->expects('getName')->andReturn('Module:Presenter');
dump($presenterMock->getName()); // returns Nette\Application\IPresenter#4

Bad exception message returned

Hi,

I found bug in returned exception, when I have simple code:

        $obj = $mockista->create("Foo");
        $obj->expects("bar")->with(1)->once();
        $obj->bar(2);

I except message of exception:

Unexpected call in mock Foo::bar(), args: array (0 => 2)

but I get:

Expected method Foo::bar() should be called exactly once but not called at all.

But if I have same code, without checking calls count:

        $obj = $mockista->create("Foo");
        $obj->expects("bar")->with(1);
        $obj->bar(2);

returned message is correct!

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.