{"id":16721167,"url":"https://github.com/khalyomede/matcha","last_synced_at":"2025-03-15T12:23:26.660Z","repository":{"id":57006189,"uuid":"137682565","full_name":"khalyomede/matcha","owner":"khalyomede","description":"Unit test library that taste good.","archived":false,"fork":false,"pushed_at":"2019-01-27T12:35:37.000Z","size":108,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T03:47:38.391Z","etag":null,"topics":["library","php","testing","unit-test"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/khalyomede/matcha","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khalyomede.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-17T19:50:01.000Z","updated_at":"2019-08-30T18:31:26.000Z","dependencies_parsed_at":"2022-08-21T12:40:40.407Z","dependency_job_id":null,"html_url":"https://github.com/khalyomede/matcha","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fmatcha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fmatcha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fmatcha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalyomede%2Fmatcha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalyomede","download_url":"https://codeload.github.com/khalyomede/matcha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243727298,"owners_count":20337968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","php","testing","unit-test"],"created_at":"2024-10-12T22:29:09.763Z","updated_at":"2025-03-15T12:23:26.638Z","avatar_url":"https://github.com/khalyomede.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matcha\n\nUnit test library that taste good.\n\n![PHP from Packagist](https://img.shields.io/packagist/php-v/khalyomede/matcha.svg)\n![Packagist](https://img.shields.io/packagist/v/khalyomede/matcha.svg)\n![Codeship](https://img.shields.io/codeship/dc9adee0-9b4e-0136-cc78-3a6df96c6020.svg)\n![Packagist](https://img.shields.io/packagist/l/khalyomede/matcha.svg)\n\n\u003cdiv style=\"text-align: center;\"\u003e\n    \u003cimg style=\"margin-left: auto; margin-right: auto;\" src=\"https://user-images.githubusercontent.com/15908747/41511668-c68e330e-727b-11e8-89b6-c18d2d07af18.png\" alt=\"Matcha logo\" height=\"90px\" /\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n![Gif of an example of usage](https://image.ibb.co/eKPpjU/landing-page-matcha-v-0-13-1.gif)\n\n## Summary\n\n- [Installation](#installation)\n- [Examples](#examples)\n- [Full example](#full-example)\n- [API](#api)\n- [Credits](#credits)\n\n## Installation\n\nIn your project root folder:\n\n```bash\ncomposer require --dev khalyomede/matcha:0.*\n```\n\n## Examples\n\n- [Example 1: testing if a code returns a string](#example-1-testing-if-a-code-returns-a-string)\n- [Example 2: testing if a value is true](#example-2-testing-if-a-code-returns-true)\n- [Example 3: testing if a code returns null](#example-3-testing-if-a-code-returns-null)\n- [Example 4: testing the negativity of an expression](#example-4-testing-the-negativity-of-an-expression)\n- [Example 5: testing if a message has been displayed](#example-5-testing-if-a-message-has-been-displayed)\n- [Example 6: testing if a variable returns the desired type](#example-6-testing-if-a-variable-returns-the-desired-type)\n- [Example 7: testing against a string format](#example-7-testing-against-a-string-format)\n- [Example 8: testing if a database is reachable](#example-8-testing-if-a-database-is-reachable)\n- [Example 9: make the console report detailed](#example-9-make-the-console-report-detailed)\n- [Example 10: using matcha console command on a single file](#example-10-using-matcha-console-command-on-a-single-file)\n- [Example 11: using matcha console command on a folder](#example-11-using-matcha-console-command-on-a-folder)\n\n### Example 1: testing if a code returns a string\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('trim', function() {\n  it('should return the same string if the string has no spaces around', function() {\n    expect( trim('hello world') )-\u003etoBe()-\u003eequalTo('hello world');\n  });\n});\n\nreturn run();\n```\n\n### Example 2: testing if a value is true\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('empty', function() {\n  it('should return true if the string has no characters', function() {\n    expect( empty('') )-\u003etoBe()-\u003etrue();\n  });\n});\n\nreturn run();\n```\n\n### Example 3: testing if a code returns false\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('isset', function() {\n  it('should return false if the variable does not exists', function() {\n    expect( isset($GLOBALS['php6']) )-\u003etoBe()-\u003efalse();\n  });\n});\n\nreturn run();\n```\n\n### Example 4: testing the negativity of an expression\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('array-sum', function() {\n  it('should not return null', function() {\n    expect( array_sum([1, 2, 3]) )-\u003enot()-\u003etoBe()-\u003enull();\n  });\n});\n\nreturn run();\n```\n\n### Example 5: testing if a message has been displayed\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('echo', function() {\n  it('it should display the correct message', function() {\n    expect(function() {\n      echo 'hello world';\n    })-\u003etoDisplay('hello world');\n  });\n});\n\nreturn run();\n```\n\n### Example 6: testing if a variable returns the desired type\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('empty', function() {\n  it('it should return true if an array is empty', function() {\n    expect( empty([]) )-\u003etoBe()-\u003eaBoolean();\n  });\n});\n\nreturn run();\n```\n\n### Example 7: testing against a string format\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('json', function() {\n  it('should be a valid json string', function() {\n    expect('{\"hello\": \"world\"}')-\u003etoBe()-\u003eaString()-\u003einJsonFormat();\n  });\n});\n\nreturn run();\n```\n\n### Example 8: testing if a database is reachable\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('database connectivity', function() {\n  it('should be reachable', function() {\n    expect([\n      'driver' =\u003e 'mysql', \n      'host' =\u003e 'ensembldb.ensembl.org', \n      'user' =\u003e 'anonymous'\n    ])-\u003etoBe()-\u003eaDatabase()-\u003ethatIsAccessible();\n  });\n});\n\nreturn run();\n```\n\n### Example 9: make the console report detailed\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\nuse Khalyomede\\ReportLevel;\n\ndescribe('array', function() {\n  it('should merge two arrays', function() {\n    expect( array_merge([1, 2, 3], [4, 5, 6]) )-\u003etoBe()-\u003eequalTo([1, 2, 3, 4, 5, 6]);\n  });\n\n  it('should diff two array', function() {\n    expect( array_count_values([1, 1, 3]) )-\u003etoBe()-\u003eequalTo([1 =\u003e 2, 3 =\u003e 1]);\n  });\n\n  it('should shuffle an array', function() {\n    $array = [1, 2];\n\n    expect( shuffle($array) )-\u003etoBe()-\u003eanArray();\n  });\n});\n\nreport('detailed');\n// or\nreport(ReportLevel::DETAILED);\n\nreturn run();\n```\n\n### Example 10: using matcha console command on a single file\n\n```php\nuse function Khalyomede\\Style\\expect;\n\ndescribe('abs', function() {\n  it('it should give the absolute value for a positive value', function() {\n    expect(abs(-10 + 2))-\u003etoBe()-\u003eequalTo(8);\n  });\n\n  it('should give the absolute value for a positive value', function() {\n    expect(abs(10 + 2))-\u003etoBe()-\u003eequalTo(12);\n  });\n});\n```\n\n```bash\n$ bin/matcha example/tests/example-10.php\n\n  2018-10-13 18:55:11.628200  ⓘ  Running tests for \"abs\"\n  2018-10-13 18:55:11.630700  ⚐  2 tests completed, 0 tests failed\n  2018-10-13 18:55:11.630800  ⚐  tests ran in 0.0015 sec. (+0.0018 sec.)\n  2 / 2 ▓▓ 100 %\n```\n\n### Example 11: using matcha console command on a folder\n\n_Check /example/tests, all the files that ends with `.php`. You are not constraint by the extension `.test.php`, you can ommit it._\n\n```bash\n$ bin/matcha example/tests/\n\n  2018-10-13 18:58:05.348300  ⓘ  Running tests for \"abs\"\n  2018-10-13 18:58:05.351300  ⓘ  Running tests for \"array_sum\"\n  2018-10-13 18:58:05.351400  ⓘ  Running tests for \"count\"\n  2018-10-13 18:58:05.351500  ⚐  8 tests completed, 0 tests failed\n  2018-10-13 18:58:05.351500  ⚐  tests ran in 0.0019 sec. (+0.0022 sec.)\n  8 / 8 ▓▓▓▓▓▓▓▓ 100 %\n```\n\n## Full example\n\nThis example is intended to show you how can all of these function can be mixed together.\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('trim', function() {\n  it('should return a string when triming a string', function() {\n    expect(trim('hello world'))-\u003etoBe()-\u003eaString();\n  });\n\n  it('should return a string even if triming null', function() {\n    expect(trim(null))-\u003etoBe()-\u003eaString();\n  });\n\n  it('should return the same string when triming a string without spaces around', function() {\n    expect(trim('hello world'))-\u003etoBe()-\u003eequalTo('hello world');\n  });\n\n  it('should return the string without spaces around if triming a string with spaces around', function() {\n    expect(trim(' hello world '))-\u003etoBe()-\u003eequalTo('hello world');\n  });\n});\n\ndescribe('empty', function() {\n  it('should return true if checking null', function() {\n    expect(empty(null))-\u003etoBe()-\u003estrictly()-\u003etrue();\n  });\n\n  it('should return true if checking false', function() {\n    expect(empty(false))-\u003etoBe()-\u003etrue();\n  });\n\n  it('should return true if checking an empty array', function() {\n    expect(empty([]))-\u003etoBe()-\u003etrue();\n  });\n});\n\ndescribe('isset', function() {\n  it('should return false if a variable is not set', function() {\n    expect(isset($php6))-\u003etoBe()-\u003efalse();\n  });\n\n  it('should return true if an array is set', function() {\n    expect(isset($_GET))-\u003etoBe()-\u003etrue();\n  });\n});\n\nreturn run();\n```\n\n## API\n\n- [describe](#describe)\n- [expect](#expect)\n  - [not](#not)\n  - [strictly](#strictly)\n  - [toBe](#tobe)\n    - [aBoolean](#aBoolean)\n    - [aDatabase](#aDatabase)\n      - [thatIsAccessible](#thatIsAccessible)\n    - [aDouble](#aDouble)\n    - [aFile](#aFile)\n    - [aFloat](#aFloat)\n    - [aFunction](#aFunction)\n    - [anArray](#anArray)\n    - [anObject](#anObject)\n    - [anInstanceOf](#anInstanceOf)\n    - [anInteger](#anInteger)\n    - [aResource](#aResource)\n    - [aString](#aString)\n      - [inJsonFormat](#inJsonFormat)\n    - [equalTo](#equalto)\n      - [false](#false)\n      - [null](#null)\n      - [true](#true)\n  - [toDisplay](#toDisplay)\n  - [toThrow](#toThrow)\n    - [theException](#theException)\n    - [theMessage](#theMessage)\n- [it](#it)\n- [report](#report)\n- [run](#run)\n\n### expect\n\nReturns a new Expect instance.\n\n```php\nfunction expect($mixed): Expect\n```\n\n```php\nrequire(__DIR__  '/../vendor/autoload.php');\n\nuse function Khalyomede\\Expect;\n\nexpect( empty('hello world') );\n```\n\n```php\nrequire(__DIR__  '/../vendor/autoload.php');\n\nuse function Khalyomede\\Expect;\n\nexpect(function() {\n  throw new Exception('exception manually thrown');\n});\n```\n\n### not\n\nAsserts that we expect the inverse of the test.\n\n```php\npublic function not(): Expect\n```\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('empty', function() {\n  it('should not return true if the string is not empty', function() {\n    expect( empty('hello world') )-\u003enot()-\u003etoBe()-\u003etrue();\n  });\n});\n\nreturn run();\n```\n\n### strictly\n\nAsserts that we expect the test to be also type-tested (this will prevent from PHP to perform implicit cast when running the test).\n\n```php\npublic function strictly(): Expect\n```\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('int cast', function() {\n  it('should return the integer equivalent of the string representation of a number', function() {\n    expect((int) '1')-\u003etoBe()-\u003estrictly()-\u003eequalTo(1);\n  });\n});\n\nreturn run();\n```\n\n### toBe\n\nAsserts that we are testing an equality.\n\n```php\npublic function toBe(): Expect\n```\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('trim', function() {\n  it('should return the same string if it has no spaces around', function() {\n    expect( trim('hello world') )-\u003etoBe()-\u003eequalTo('hello world');\n  });\n});\n\nreturn run();\n```\n\n### equalTo\n\nAsserts that we are testing an equality against a particular value.\n\n```php\npublic function equalTo($mixed): Expect\n```\n\n```php\nrequire(__DIR__ . '/../vendor/autoload.php');\n\nuse function Khalyomede\\Style\\expect;\n\ndescribe('implicit cast', function() {\n  it('should implicitly cast the string representation of a number', function() {\n    expect('1')-\u003etoBe()-\u003eequalTo(1)\n  });\n});\n\nreturn run();\n```\n\n### Report\n\nUpdate the level of report in console.\n\n```php\nfunction report(string $level): void\n```\n\nAvailable reports levels are `detailed`, `normal` (by default) and `reduced`.\n\nReports levels can be used through `Khalyomede\\ReportLevel` class:\n\n```php\nuse Khalyomede\\ReportLevel;\n\nReportLevel::DETAILED;\nReportLevel::NORMAL;\nReportLevel::REDUCED;\n```\n\n## Credits\n\n- Logo by [Made](https://thenounproject.com/made.somewhere/) from [Noun project](https://thenounproject.com/) (modified version of logo is currenctly used, check out the [original version](https://thenounproject.com/term/green-tea/952777/))","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fmatcha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalyomede%2Fmatcha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalyomede%2Fmatcha/lists"}