All Projects → mnapoli → Phpunit Easymock

mnapoli / Phpunit Easymock

Licence: mit
Build PHPUnit mocks easily

Projects that are alternatives of or similar to Phpunit Easymock

hubtel-payment
🎉A comprehensive PHP Client Package for consuming the Hubtel Payment API
Stars: ✭ 13 (-64.86%)
Mutual labels:  phpunit, tests
Brainmonkey
Mocking utility for PHP functions and WordPress plugin API
Stars: ✭ 191 (+416.22%)
Mutual labels:  phpunit, tests
Nyancat Phpunit Resultprinter
Nyan Cat result printer for PHPUnit
Stars: ✭ 288 (+678.38%)
Mutual labels:  phpunit, tests
phpunit-injector
Injects services from a PSR-11 dependency injection container to PHPUnit test cases
Stars: ✭ 62 (+67.57%)
Mutual labels:  phpunit, tests
Unit Testing Tips
Unit testing tips by examples in PHP
Stars: ✭ 318 (+759.46%)
Mutual labels:  phpunit, tests
Fakeit
The Kotlin fake data generator library!
Stars: ✭ 482 (+1202.7%)
Mutual labels:  tests
Phpunit Watcher
A tool to automatically rerun PHPUnit tests when source code changes
Stars: ✭ 700 (+1791.89%)
Mutual labels:  phpunit
Php Source Query
🐘 PHP library to query servers that implement Steam query protocol (also known as Source Engine Query protocol)
Stars: ✭ 461 (+1145.95%)
Mutual labels:  phpunit
Storybook Addon Specifications
📖 Write tests next to your stories and display their results inside storybook interface
Stars: ✭ 453 (+1124.32%)
Mutual labels:  tests
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+94886.49%)
Mutual labels:  tests
Atom Mocha Test Runner
Run your Atom package tests using Mocha
Stars: ✭ 10 (-72.97%)
Mutual labels:  tests
Phpunit Speedtrap
Reports on slow-running tests in your PHPUnit test suite
Stars: ✭ 688 (+1759.46%)
Mutual labels:  phpunit
Role Acl
Role based access control using actions, attributes and sync and async conditions
Stars: ✭ 502 (+1256.76%)
Mutual labels:  tests
Tddd
A Laravel Continuous Integration Package
Stars: ✭ 722 (+1851.35%)
Mutual labels:  phpunit
Laravel Vue Boilerplate
🐘 A Laravel 6 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.
Stars: ✭ 472 (+1175.68%)
Mutual labels:  phpunit
Capture Stream
Capture stream output.
Stars: ✭ 10 (-72.97%)
Mutual labels:  tests
Codeception
Full-stack testing PHP framework
Stars: ✭ 4,401 (+11794.59%)
Mutual labels:  phpunit
Doctrine Test Bundle
Symfony bundle to isolate your app's doctrine database tests and improve the test performance
Stars: ✭ 689 (+1762.16%)
Mutual labels:  phpunit
Phpqa
Docker image that provides static analysis tools for PHP
Stars: ✭ 853 (+2205.41%)
Mutual labels:  phpunit
Budget
Get a grip on your finances.
Stars: ✭ 609 (+1545.95%)
Mutual labels:  phpunit

PHPUnit EasyMock

Helpers to build PHPUnit mock objects easily.

Total Downloads

Why?

This library is not a mocking library. It's just a few helpers to write the most common mocks more easily.

It doesn't reinvent anything and is not intended to cover every use case: only the most common ones.

Installation

$ composer require --dev mnapoli/phpunit-easymock

To be able to use EasyMock in your tests you must include the trait in your class:

class MyTest extends \PHPUnit\Framework\TestCase
{
    use \EasyMock\EasyMock;

    // ...
}

Usage

Here is what a very common PHPUnit mock looks like:

$mock = $this->createMock('My\Class');

$mock->expect($this->any())
    ->method('sayHello')
    ->willReturn('Hello');

Yuck!

Here is how to write it with EasyMock:

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);

What if you want to assert that the method is called once (i.e. $mock->expect($this->once()))? Use spy() instead:

$mock = $this->easySpy('My\Class', [
    'sayHello' => 'Hello',
]);

Features

You can mock methods so that they return values:

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'Hello',
]);

Or so that they use a callback:

$mock = $this->easyMock('My\Class', [
    'sayHello' => function ($name) {
        return 'Hello ' . $name;
    },
]);

You can also have methods throw exceptions by providing an Exception instance:

$mock = $this->easyMock('My\Class', [
    'sayHello' => new \RuntimeException('Whoops'),
]);

It is possible to call the mock() method again on an existing mock:

$mock = $this->easyMock('My\Class');

$mock = $this->easyMock($mock, [
    'sayHello' => 'Hello',
]);

What if?

If you want to use assertions or other PHPUnit features, just do it:

$mock = $this->easyMock('My\Class', [
    'sayHello' => 'hello',
]);

$mock->expects($this->once())
    ->method('sayGoodbye')
    ->willReturn('Goodbye');

Mocks are plain PHPUnit mocks, nothing special here.

Contributing

See the CONTRIBUTING file.

License

Released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].