Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pluf/test
Basci mock object which are used int unit tests
https://github.com/pluf/test
Last synced: about 1 month ago
JSON representation
Basci mock object which are used int unit tests
- Host: GitHub
- URL: https://github.com/pluf/test
- Owner: pluf
- License: other
- Created: 2017-10-06T19:59:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-06-22T00:47:35.000Z (over 3 years ago)
- Last Synced: 2024-10-01T08:02:20.676Z (about 2 months ago)
- Language: PHP
- Size: 594 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pluf Test
[![Build Status](https://travis-ci.com/pluf/test.svg?branch=master)](https://travis-ci.com/pluf/test)
[![codecov](https://codecov.io/gh/pluf/test/branch/master/graph/badge.svg)](https://codecov.io/gh/pluf/test)
[![Maintainability](https://api.codeclimate.com/v1/badges/513f356bdf26065cc009/maintainability)](https://codeclimate.com/github/pluf/test/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/513f356bdf26065cc009/test_coverage)](https://codeclimate.com/github/pluf/test/test_coverage)
[![Coverage Status](https://coveralls.io/repos/github/pluf/test/badge.svg?branch=master)](https://coveralls.io/github/pluf/test?branch=master)This tutorial assumes that you use PHP 7.3 or PHP 7.4. You will learn how to write simple unit tests as well as how to download and run PlufTest.
PlufTest is based on PHPUnit 8.
## Install
You can add Pluf/Test as a local, per-project, development-time dependency to your project using Composer:
➜ composer require --dev pluf/test ^6
➜ ./vendor/bin/pluftest --version
Pluf/Test 6.0.0 by pluf.ir and contributors.The example shown above assumes that composer is on your $PATH.
Your composer.json should look similar to this:
{
"autoload": {
"classmap": [
"src/"
]
},
"require-dev": {
"pluf/test": "^9"
}
}## Test Code
suppose there is a code
src/Email.php
with content:
ensureIsValidEmail($email);
$this->email = $email;
}
public static function fromString(string $email): self
{
return new self($email);
}
public function __toString(): string
{
return $this->email;
}
private function ensureIsValidEmail(string $email): void
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException(
sprintf(
'"%s" is not a valid email address',
)
);
}
}
}Create a file:
tests/EmailTest.php
And create the test class
assertInstanceOf(
Email::class,
Email::fromString('[email protected]')
);
}
public function testCannotBeCreatedFromInvalidEmailAddress(): void
{
$this->expectException(InvalidArgumentException::class);
Email::fromString('invalid');
}
public function testCanBeUsedAsString(): void
{
$this->assertEquals(
'[email protected]',
Email::fromString('[email protected]')
);
}
}
The test is readyNote: Do not put tests in a namespace.
## Run the test
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/EmailTest
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.
... 3 / 3 (100%)
Time: 70 ms, Memory: 10.00MB
OK (3 tests, 3 assertions)--bootstrap vendor/autoload.php instructs the PHPUnit command-line test runner to include vendor/autoload.php before the tests are run.
tests/EmailTest instructs the PHPUnit command-line test runner to execute the tests of the EmailTest class that is declared in tests/EmailTest.php.
Using tests instead of tests/EmailTest would instruct the PHPUnit command-line test runner to execute all tests found declared in *Test.php sourcecode files in the tests directory.
## Contributing
If you would like to contribute to Pluf, please read the README and CONTRIBUTING documents.
The most important guidelines are described as follows:
>All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch, and send us a pull request.
To ensure a consistent code base, you should make sure the code follows the PSR-2 Coding Standards.