2017 © Pedro Peláez
 

library chubbyphp-mock

Chubbyphp Mock

image

chubbyphp/chubbyphp-mock

Chubbyphp Mock

  • Saturday, July 28, 2018
  • by dominikzogg
  • Repository
  • 0 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

chubbyphp-mock

CI Coverage Status Mutation testing badge Latest Stable Version Total Downloads Monthly Downloads, (*1)

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities, (*2)

Description

A helper trait simplify mocking within phpunit., (*3)

Requirements

  • php: ^8.1
  • phpunit/phpunit: ^10.4.2

Installation

Through Composer as chubbyphp/chubbyphp-mock., (*4)

composer require chubbyphp/chubbyphp-mock "^1.7" --dev

Usage

<?php

declare(strict_types=1);

namespace MyProject\Tests;

use Chubbyphp\Mock\Argument\ArgumentCallback;
use Chubbyphp\Mock\Argument\ArgumentInstanceOf;
use Chubbyphp\Mock\Call;
use Chubbyphp\Mock\MockByCallsTrait;
use MyProject\Services\DateTimeService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
{
    use MockByCallsTrait;

    public function testExecute()
    {
        /** @var DateTimeService|MockObject $dateTimeService */
        $dateTimeService = $this->getMockByCalls(DateTimeService::class, [
            Call::create('format')
                ->with(new ArgumentInstanceOf(\DateTime::class), 'c'),
                ->willReturn('2004-02-12T15:19:21+00:00')
            Call::create('format')
                ->with(
                    new ArgumentCallback(function ($dateTime) {
                        self::assertInstanceOf(\DateTime::class, $dateTime);
                    }),
                    'c'
                )
                ->willReturn('2008-05-23T08:12:55+00:00')
        ]);

        self::assertSame('2004-02-12T15:19:21+00:00' , $dateTimeService->format(new \DateTime(), 'c'));
        self::assertSame('2008-05-23T08:12:55+00:00' , $dateTimeService->format(new \DateTime(), 'c'));
    }
}

FAQ

Expectation failed for method name is anything when invoked n... time(s).

There is a mock with $calls given, but no method get called on the mock., (*5)

/** @var User|MockObject $user */
$user = $this->getMockByCalls(User::class, [
    Call::create('getId')->with()->willReturn('a656cca7-7363-4ba7-875d-74bb0fd4f543'),
]);

// uncomment and test will be green
//$user->getId();

2024 Dominik Zogg, (*6)

The Versions

28/07 2018

dev-master

9999999-dev

Chubbyphp Mock

  Sources   Download

MIT

The Requires

 

by Dominik Zogg

mock phpunit slim chubbyphp

28/07 2018

1.0-beta1

1.0.0.0-beta1

Chubbyphp Mock

  Sources   Download

MIT

The Requires

 

by Dominik Zogg

mock phpunit slim chubbyphp