PHPackages                             ostark/craft-mockery - 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. ostark/craft-mockery

AbandonedArchivedLibrary

ostark/craft-mockery
====================

Mockery for Craft

019[2 issues](https://github.com/ostark/craft-mockery/issues)PHP

Since Jan 2Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ostark/craft-mockery)[ Packagist](https://packagist.org/packages/ostark/craft-mockery)[ RSS](/packages/ostark-craft-mockery/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Mockery for Craft Plugins and Modules
=====================================

[](#mockery-for-craft-plugins-and-modules)

This package helps with mocking objects in Craft using Mockery. It's made for plugins or modules that do not touch the database heavily. In contrast to [fixtures](https://craftcms.com/docs/3.x/testing/testing-craft/fixtures.html) that define a consistent and predictable state of your test dataset, with mocking you can test different scenarios more easily with less setup efforts.

Please mind, if your code relies heavily on database CRUD operations, this is probably not the right tool for your test.

Setup
-----

[](#setup)

```
cd projects/your-plugin
composer require --dev ostark/craft-mockery

```

Make sure to load this [tests/\_bootstrap.php file](_bootstrap.example.php) with your tests. For PHPUnit your define it in phpunit.xml using the `bootstrap` property or in Codeception your .yml files.

Mock Elements
-------------

[](#mock-elements)

```
ostark\CraftMockery\Element::make(\craft\elements\Entry::class);
ostark\CraftMockery\Element::make(\craft\elements\Category::class);

```

Mock Records
------------

[](#mock-records)

```
ostark\CraftMockery\Record::make(\craft\elements\Entry::class);
ostark\CraftMockery\Record::make(\craft\elements\Category::class);

```

Mock Services
-------------

[](#mock-services)

```
ostark\CraftMockery\Service::all();

```

Mock Queries
------------

[](#mock-queries)

```
\ostark\CraftMockery\Query::make(\craft\db\Query::class);

```

Expectations
------------

[](#expectations)

The actual results are stored in simple php files which named after the class name. The location for these files is `tests/expectations`. Here is an example of an `Entry.php` file:

```
