Download the PHP package scheb/in-memory-data-storage without Composer
On this page you can find all versions of the php package scheb/in-memory-data-storage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download scheb/in-memory-data-storage
More information about scheb/in-memory-data-storage
Files in scheb/in-memory-data-storage
Package in-memory-data-storage
Short Description A simple in-memory data storage
License MIT
Homepage https://github.com/scheb/in-memory-data-storage
Informations about the package in-memory-data-storage
scheb/in-memory-data-storage
A fast in-memory data storage in plain PHP. It can be used as a test double for a database, in order to to decouple the test cases from the database and speeding them up.
Features
- CRUD operations
- Convenience methods for data selection and manipulation
- Named items
Installation
How to use
You can find an executable example in the doc
folder.
Customization
ItemNotFoundException
Single-item (read, update, remove) operations will handle gracefully, when there is no matching item in the data store.
Reads will return null
, update/remove won't change anything. If you want such cases to raise an exception instead, you
can configure that behavior with the builder for each type of operation.
Data Store
The library comes with a simple array-based storage, but you exchange the data storage engine with whatever you like, by
implementing Scheb\InMemoryDataStorage\DataStorage\DataStorageInterface
. Then, pass an instance to the builder:
Value Matching
Values are checked for equality with PHP's ===
operation. If you want it to use the less-strict ==
operator, you can
change the behavior with the builder.
The library integrates scheb/comparator
to check values for equality. If you need custom comparison rules, implement
Scheb\Comparator\ValueComparisonStrategyInterface
and pass your comparision strategy to the builder.
You can add as many comparision strategies as you need. They'll be checked in the order they're added and will take preference over the default comparision strategy.
If you want to implement the comparision logic completely on your own, implement
Scheb\InMemoryDataStorage\Matching\ValueMatcherInterface
and pass an instance to the builder:
Property Access
Properties are read and written with the following access strategies:
- Array access
- Public properties
- Camel-case getters an setters
If none of these works on a value object, it's either using null
(in case of read) or fails with an exception (in case
of write).
If you want to implement the property access logic completely on your own, implement
Scheb\PropertyAccess\PropertyAccessInterface
and pass an instance to the builder:
Contribute
You're welcome to contribute to this library by creating a pull requests or feature request in the issues section. For pull requests, please follow these guidelines:
- Symfony code style
- PHP7.1 type hints for everything (including: return types,
void
, nullable types) - Please add/update test cases
- Test methods should be named
[method]_[scenario]_[expected result]
To run the test suite install the dependencies with composer install
and then execute bin/phpunit
.
License
This bundle is available under the MIT license.