Comments (7)
Works for me, try to add this test:
public function test_issue_4() {
$this->object->expects('bar')->with(1)->once();
try {
$this->object->bar(2);
$this->object->assertExpectations();
} catch (\Mockista\MockException $e) {
$this->assertEquals("Unexpected call in mock unnammed::bar(), args: array (\n 0 => 2,\n)", $e->getMessage());
return;
}
$this->fail('No exception thrown');
}
If you are able to write failing test, I would try to fix that.
from mockista.
So, I'm sorry it is error on my side ... I use your BaseTestCase sample, where Mockista\Registry is used and error is in "$this->mockista->assertExpectations()" call..
This crash - "Mockista\MockException: Expected method unnamed::bar() should be called exactly once but not called at all."
class MockerTest extends \Tester\TestCase
{
/** @var \Mockista\Registry */
protected $mockista;
protected $object;
protected function setUp()
{
$this->mockista = new \Mockista\Registry();
}
protected function tearDown()
{
$this->mockista->assertExpectations(); // When I comment this, test is correct!
}
public function testIssue4() {
$this->object = $this->mockista->create();
$this->object->expects('bar')->with(1)->once();
try {
$this->object->bar(2);
$this->object->assertExpectations();
} catch (\Mockista\MockException $e) {
Assert::equal("Unexpected call in mock unnammed::bar(), args: array (\n 0 => 2,\n)", $e->getMessage());
return;
}
$this->fail('No exception thrown');
}
}
from mockista.
So it's really problem in Nette/Tester, I still don't know why and I suppose you don't use it. But in Nette/Tester is problem in TestCase (base class of all tests), in this method of TestCase:
/**
* Runs the single test.
* @return void
*/
public function runTest($name, array $args = array())
{
$this->setUp();
try {
call_user_func_array(array($this, $name), $args);
} catch (\Exception $e) {
}
$this->tearDown();
if (isset($e)) {
throw $e;
}
}
This cause that is returned invalid exception: "Expected method unnamed::bar() should be called exactly once but not called at all."
But when I move calling tearDown method inside try/catch:
/**
* Runs the single test.
* @return void
*/
public function runTest($name, array $args = array())
{
$this->setUp();
try {
call_user_func_array(array($this, $name), $args);
$this->tearDown();
} catch (\Exception $e) {
}
if (isset($e)) {
throw $e;
}
}
It throw correct exception ... it's magic :)
from mockista.
It seems that problem is that assertExpectations is called twice - first call "resets" the previous calls, hence this message.
from mockista.
If you call assertExpectations in tearDown method, you don't have to call it in your tests. It's called automatically for you.
from mockista.
I'm sorry, I placed bad sample code here. When I remove call "assertExpectations" in test's method, it still throw bad exception. For test I dumped mock in assertExpectations and it's really call only once, so there isn't problem. But problem really will be in implements with Nette/Tester.
from mockista.
Heureka! I found error, when method "bar" is called, it throw correct Exception with invalid arguments. But this exception is catch in "runTest" method. After it is call tearDown method and throw Exception with invalid count of calls, which isn't catch.
from mockista.
Related Issues (14)
- create tag HOT 2
- Validace volaných parametrů. HOT 14
- Declaration of __call() should be compatible with... HOT 3
- CreateMock doesn't generate unique class name
- Not working mocking of internal classes HOT 1
- Wrong expectations assert (maybe my misuse) HOT 5
- ProxyMock - mock that intercepts calls to existing object HOT 8
- Wrong mock for class with getName() method HOT 2
- ValueMatcher - match every item independently
- Does mockista check the existence of expected method? HOT 10
- Current implementation of dumping arguments when mathod not match kills phpunit/php/everything HOT 6
- New release including Matchers HOT 3
- Support for PHP 7 scalar typehints?
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 mockista.