PHPackages                             thanos-kontos/amock - 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. thanos-kontos/amock

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

thanos-kontos/amock
===================

PHPunit mock fixtures

0.0.3(8y ago)14MITPHPPHP &gt;=7.1

Since Oct 31Pushed 8y ago2 watchersCompare

[ Source](https://github.com/thanosKontos/amock)[ Packagist](https://packagist.org/packages/thanos-kontos/amock)[ RSS](/packages/thanos-kontos-amock/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Amock - Organize your stub objects in yaml
==========================================

[](#amock---organize-your-stub-objects-in-yaml)

[![Latest Stable Version](https://camo.githubusercontent.com/8a1d8bc5bb0c473ccf29a211deae66ea4b81f0e784bc61a6f5474ddde3074293/68747470733a2f2f706f7365722e707567782e6f72672f7468616e6f732d6b6f6e746f732f616d6f636b2f762f737461626c65)](https://packagist.org/packages/thanos-kontos/amock)[![Build Status](https://camo.githubusercontent.com/a4c97b7fcf0ee4e411bd708d35540965a88fe23db060c6689b65e61f7bd0a618/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7468616e6f734b6f6e746f732f616d6f636b2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thanosKontos/amock/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/567a86bf33a1e19cf3a7be0b7f5bc0f1529c2d04b70556bf6d5f26f8615ffa2b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7468616e6f734b6f6e746f732f616d6f636b2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thanosKontos/amock/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/57ac859cad8b3fa993df5c0e317e4feb8ef4f0c8295da487211f4093ce642416/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7468616e6f734b6f6e746f732f616d6f636b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/thanosKontos/amock/?branch=master)

Release notes
-------------

[](#release-notes)

**Still not 100% stable. Use with caution**

At a glance
-----------

[](#at-a-glance)

Quoting from phpunit:

> Sometimes it is just plain hard to test the system under test (SUT) because it depends on other components that cannot be used in the test environment. This could be because they aren't available, they will not return the results needed for the test or because executing them would have undesirable side effects. In other cases, our test strategy requires us to have more control or visibility of the internal behavior of the SUT.

> When we are writing a test in which we cannot (or chose not to) use a real depended-on component (DOC), we can replace it with a Test Double. The Test Double doesn't have to behave exactly like the real DOC; it merely has to provide the same API as the real one so that the SUT thinks it is the real one!

It is almost impossible to write good tests without stubbing objects, because we often need to imitate writing to a database or calling an external service.

*Amock* lets you create these stub objects in yaml instead of "polluting" your tests with irrelevant code.

Instructions
------------

[](#instructions)

`composer require --dev thanos-kontos/amock`

Add a directory to store your fixtures e.g. `tests/mock_fixtures` and as as many yaml files as you want.

```
# tests/mock_fixtures/repositories.yml

MyProject\Library\UserRepository:
  mockUserRepository:
    disableConstructor: true
    mockMethods:
      insert: '@null'
      update: '@null'
MyProject\Library\ProductRepository:
  mockProductRepository:
    disableConstructor: true
    mockMethods:
      insert: '@null'
      update: '@null'
```

```
# tests/mock_fixtures/gateways.yml

MyProject\Library\SomeApiGateway:
  mockSuccessResponse:
    disableConstructor: true
    mockMethods:
      getHelloReponse: '@string:{"hello":"world"}'
  mock404Response:
    disableConstructor: true
    mockMethods:
      getHelloReponse: '@string:{"error": "404","message":"Not found"}'
      sampleSetter: '@self'
      methodThatReturnsDifferentValueOnConsecutiveCalls:
        - '@string:{"hello":"world"}'
        - '@integer:123'
        - '@boolean:false'
      methodThatReturnsArray: '@array:{"111":"aaa","222":"bbb"}'
      methodThatReturnsBoolean: '@boolean:false'
      methodThatReturnsInteger: '@integer:123'
      methodThatReturnsNull: '@null'
  mockExceptionResponse:
    disableConstructor: true
    mockMethods:
      getHelloReponse: '@exception:\MyProject\Library\Exception\ApiException'
```

On your test setUp method

```
$config = new \Amock\Configuration('yaml', 'dir', '/path/to/mock_fixtures');
$this->amock = \Amock\Amock::create($config, $testCase);
```

or

```
$config = new \Amock\Configuration('yaml', 'file', '/path/to/mock_fixtures/somefile.yml');
$this->amock = \Amock\Amock::create($config, $testCase);
```

Then you can use the configured mocks in your tests:

```
$stub = $this->amock->get('mock404Response');
```

Example
=======

[](#example)

There is an dummy project [here](https://github.com/thanosKontos/amock-example) that you can use as a reference.

License
-------

[](#license)

Amock is released under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~8 days

Total

3

Last Release

3147d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca6787a3ed580f3af77e98b2ab05f919cf39ab8bfe6bc27e7ba5ff240441385d?d=identicon)[tkontos](/maintainers/tkontos)

---

Top Contributors

[![thanosKontos](https://avatars.githubusercontent.com/u/4849965?v=4)](https://github.com/thanosKontos "thanosKontos (30 commits)")

---

Tags

phpunittestFixturemock

### Embed Badge

![Health badge](/badges/thanos-kontos-amock/health.svg)

```
[![Health](https://phpackages.com/badges/thanos-kontos-amock/health.svg)](https://phpackages.com/packages/thanos-kontos-amock)
```

###  Alternatives

[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69619.1M606](/packages/spatie-phpunit-snapshot-assertions)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.7M511](/packages/php-mock-php-mock-phpunit)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1489.3M94](/packages/ergebnis-phpunit-slow-test-detector)[colinodell/psr-testlogger

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

1813.2M67](/packages/colinodell-psr-testlogger)[elliotchance/concise

Concise is test framework for using plain English and minimal code, built on PHPUnit.

45224.0k4](/packages/elliotchance-concise)[icecave/isolator

Dependency injection for global functions.

351.3M29](/packages/icecave-isolator)

PHPackages © 2026

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