mockery

Laravel: Using mock instance in Customised Route::model binding

爱⌒轻易说出口 提交于 2019-12-11 06:16:11
问题 Route model binding in Laravel, helps bind an instance to the service container, to be used in a controller action. And the beautiful thing is that when I want to write tests, I can bind a mock instance to the application, which replaces what is bound to the container. - App::instance($className, $mockInstance); I have made a request to the route ( Route::get("/{class_name}") ). I want to return an instance of the class, depending on what the value of the route parameter class_name is. If the

mock module which does not exist?

旧时模样 提交于 2019-12-11 05:59:31
问题 When i run my mocha tests in my meteor app by: node_modules/.bin/mocha --compilers js:babel-core/register //..opts i get a problem when my module under test wants to import: import { Meteor } from 'meteor/meteor'; So i tried to mock it with mockery: mockery.enable(); moduleUnderTest = '../moduleUnderTest'; mockery.registerAllowable(moduleUnderTest); meteorMock = {}; mockery.registerMock('Meteor', meteorMock); Unfortunately the module cannot be found Error: Cannot find module 'meteor/meteor'

Passing a mocked object as the instance in PHPUnit/Laravel

主宰稳场 提交于 2019-12-11 05:54:13
问题 I'm mocking an object and writing a test like so... public function test_mocked_object(){ $purchase = new Purchase(); $purchase_m = \Mockery::mock($purchase); $purchase_m->shouldReceive('internalMethod')->andReturn('GOLD'); $purchase_m->testMethod('test'); } testMethod() contains a call to internalMethod() , like so... public function testMethod($string){ $this->internalMethod(); } ... but by the time execution reaches the call to $this->internalMethod() , $this is now an instance of the

Mockery not calling method from repository (interface)

筅森魡賤 提交于 2019-12-11 05:51:15
问题 I am trying to test my controller with this test (I'm using Laravel, if that matters): <?php use Zizaco\FactoryMuff\Facade\FactoryMuff; class ProjectControllerTest extends TestCase { public function setUp() { parent::setUp(); $this->mock = $this->mock('Dumminvoicing\Storage\Project\ProjectRepositoryInterface'); } public function mock($class) { $mock = Mockery::mock($class); $this->app->instance($class, $mock); return $mock; } protected function tearDown() { Mockery::close(); } public function

Mock should be called exactly 1 times but called 0 times

余生颓废 提交于 2019-12-10 15:07:19
问题 I have weird problem with Laravel 5 and PHPUnit. When I try to mock Laravel's facades (e.g. Auth, View, Mail) I always get this exception: Mockery\Exception\InvalidCountException: Method send("emails.register", array('user'=>'object(MCC\Models\Users\User)',), object(Closure)) from Mockery_0_Illuminate_Mail_Mailer should be called exactly 1 times but called 0 times. I have a problem with "should be called exactly 1 times but called 0 times." part. This is my test code: public function

php:use “Mockery” to mock a static method called in another static method

微笑、不失礼 提交于 2019-12-10 14:48:22
问题 I want to mock a static method which has been used in another method using Mokcery,Just as follows: Class SomeClass { public static function methodA() { .....; self::B(); } public static function methodB() { Do SomeThing } } if I want to mock methodB,and use methodA,the mock function doesn't work, just because methodB is used in methodA,just as below use Mockery as m; $mocktest = m::mock->('SomeClass[B]'); $mocktest->shouldReceive('B')->andReturn("expectedResult"); $mocktest->methodA(); The

Class 'Mockery' not found

一世执手 提交于 2019-12-09 15:14:18
问题 I use laravel (4.1) framework and i read "Laravel-testing-decoded", it's a ebook by Jeffrey Wey. I want to test my modal User and my method setPasswordAttribute($password) My unit-testing : <?php class UserTest extends TestCase { public function testHashesPasswordWhenSet(){ Hash::shouldReceive('make')->once()->andReturn('hashed'); $user = new User; $user->password = 'food'; $this->assertEquals('hashed', $user->password); } } But when i launch CLI : phpunit it return me a error : Fatal error:

What is the difference between overload and alias in Mockery?

﹥>﹥吖頭↗ 提交于 2019-12-09 10:53:18
问题 I am new to using Mockery and confused with the terminology alias and overload . Can anyone please explain to me when to use which? 回答1: Overload is used to create an "instance mock". This will "intercept" when a new instance of a class is created and the mock will be used instead. For example if this code is to be tested: class ClassToTest { public function methodToTest() { $myClass = new MyClass(); $result = $myClass->someMethod(); return $result; } } You would create an instance mock using

Testing a class that calls parent::function?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 14:09:26
问题 I have a model that overloads the where function. My overloaded method looks like this: public function where($column, $operator = null, $value = null, $boolean = 'and') { if (in_array($column, $this->metaFields)) { $value = '%"' . $column . '":"' . $value . '"'; $column = 'meta'; $operator = 'like'; } return parent::where($column, $operator, $value, $boolean); } Now using phpunit and mockery I am trying to test this class, I need to test my overloaded where function, all I really care about

How can I test react-native component with mocha + enzyme + chai when it's wrapped in a Provider component

被刻印的时光 ゝ 提交于 2019-12-08 10:44:12
问题 I'm using mocha, enzyme, chai and some mocking libraries to make the testing possible. So, the content of TestComponent.js is below, I configure the store and pass it to the provider, while DeskScreen is connected component: import mockery from "mockery"; import 'babel-polyfill'; import reactNativeSvgMock from "react-native-svg-mock"; mockery.enable(); mockery.registerMock("react-native-svg", reactNativeSvgMock); var DeskScreen = require( '../app/containers/DeskScreen/DeskScreen'); import