PHPackages                             trilopin/pt\_mock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. trilopin/pt\_mock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

trilopin/pt\_mock
=================

Easy mock for php testing

08.3kPHP

Since Jan 5Pushed 11y ago1 watchersCompare

[ Source](https://github.com/trilopin/pt_mock)[ Packagist](https://packagist.org/packages/trilopin/pt_mock)[ RSS](/packages/trilopin-pt-mock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/ae42d38d5e312cf04b32caaccadddcca5b8ba6a002c4e2d345edc6c4655a0b28/68747470733a2f2f7472617669732d63692e6f72672f7472696c6f70696e2f70745f6d6f636b2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/trilopin/pt_mock)[![Build status](https://camo.githubusercontent.com/28f6fd4cadbed2fac7e461835127e0077450470e3a6c2470ca59ae4b0af12104/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f70703364746873626c693579736b3779)](https://ci.appveyor.com/project/trilopin/pt-mock)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e4bd2b8ba552739b7dd7b310fb6e9567745341ce119c57e4ae7ebe539af0d003/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7472696c6f70696e2f70745f6d6f636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/trilopin/pt_mock/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/238ddf3bc15364c8cb6c3f1f035fd59095356da286ca5bd0a4c860e69e81876f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7472696c6f70696e2f70745f6d6f636b2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/trilopin/pt_mock/?branch=master)

pt\_mock
--------

[](#pt_mock)

This class works with PHP &gt;= 5.3.6. In order to run the tests, phpunit is required.

This class provides a way to mock objects when testing. Makes it simple to simulate method calls returning data based on parameters. Can raise exceptions instead of return data.

Source in \[[https://github.com/gramos74/pt\_mock](https://github.com/gramos74/pt_mock)\]

Examples
--------

[](#examples)

We have a method class that receives a object as parameter. Inside this method we will call the object method 'method\_mock' with parameter 'a' and we expect that it returns 'b'.

```
    class class_a {

        function my_method(class_b) {
            return class_b->method_mock('a');
        }

    }

    $class_b = new \Pt\Mock('Class B');
    $class_b->expects('method_mock')->with('a')->returns('b');

    $class_a = new class_a();
    echo $class_a->my_method($class_b);  // ----> 'b'
```

To check that all expectations have been accomplished :

```
$class_b->verify();     // for a instance of pt_mock
\Pt\Mock::verifyAll();  // for all mocks instantiated

```

If you want to test that the method is called two times:

```
    $class_b->expects('method_mock')->with('a')->times(2)->returns('b');
```

Sometimes you don't want to test if a method is called, you only want that if a method is called the mock object returns a value based on parameters.

```
    $class_b->stubs('method_mock')->with('a')->returns('b');

    echo $class_b->method_mock('a') ---> 'b'
    echo $class_b->method_mock('a') ---> 'b'
    echo $class_b->method_mock('a') ---> 'b'
    echo $class_b->method_mock('a') ---> 'b'
```

And sometimes you want to raise a exception instead of to return data.

```
$class_b->stubs('method_mock')->with('a')->raises(new Exception());

echo $class_b->method_mock('a') ---> raises a exception

```

Credits
-------

[](#credits)

Thanks a lot to Mathias Biilmann \[\] by the original idea. Was a awesome experience work together !

License
-------

[](#license)

Copyright (c) 2011 Released under the MIT license (see MIT-LICENSE) Gabriel Ramos

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/04b000d7e5e604305fb5e5f26da7a4f740864052aad2e1443a597bd096b4f3a5?d=identicon)[trilopin](/maintainers/trilopin)

---

Top Contributors

[![trilopin](https://avatars.githubusercontent.com/u/4096774?v=4)](https://github.com/trilopin "trilopin (9 commits)")[![gramos74](https://avatars.githubusercontent.com/u/564281?v=4)](https://github.com/gramos74 "gramos74 (3 commits)")[![gabiticketea](https://avatars.githubusercontent.com/u/2337178?v=4)](https://github.com/gabiticketea "gabiticketea (1 commits)")

### Embed Badge

![Health badge](/badges/trilopin-pt-mock/health.svg)

```
[![Health](https://phpackages.com/badges/trilopin-pt-mock/health.svg)](https://phpackages.com/packages/trilopin-pt-mock)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M571](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
