Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/everzet/persisted-objects
Stupid PHP library to do very simple persistance for test automation purposes
https://github.com/everzet/persisted-objects
Last synced: 8 days ago
JSON representation
Stupid PHP library to do very simple persistance for test automation purposes
- Host: GitHub
- URL: https://github.com/everzet/persisted-objects
- Owner: everzet
- Created: 2014-12-16T19:06:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-10-10T09:11:33.000Z (about 5 years ago)
- Last Synced: 2024-10-15T13:25:48.973Z (23 days ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 130
- Watchers: 7
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Persisted Objects
This repository is a collection of repositories (pun intended) that somebody might find useful
in training or testing exercises. They provide an easy way to create Fakes for your repositories
in the test infrastructure.### Why?
As stated in the header - for testing and demo purposes. These repos are optimised for cases where
you have less than 20 records in your repository and there's always only one user accessing it at
a time. In these particular cases these repositories are faster. But in every other instance
they're exponentially not.### Usage
Install with:
```
$> composer require --dev everzet/persisted-objects
```Use like this:
```php
$repo = new FileRepository(TEMP_FILE, new AccessorObjectIdentifier('getId'));
$repo->save($user);$user === $repo->findById($user->getId());
$repo->clear();
```or like this:
```php
$repo = new InMemoryRepository(new CallbackObjectIdentifier(
function($obj) { return $obj->getFirstname() . $obj->getLastname(); }
);
$repo->save($user);$user === $repo->findById($user->getFirstname() . $user->getLastname());
$repo->clear();
```