{"id":21056026,"url":"https://github.com/xp-framework/test","last_synced_at":"2026-01-19T06:04:01.962Z","repository":{"id":65329953,"uuid":"584493566","full_name":"xp-framework/test","owner":"xp-framework","description":"Tests for the XP Framework","archived":false,"fork":false,"pushed_at":"2025-12-13T10:06:16.000Z","size":203,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-15T00:10:31.663Z","etag":null,"topics":["annotations","assertions","php7","php8","testcase","testing","unittest","xp-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-02T18:14:21.000Z","updated_at":"2025-12-13T10:03:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"fd1789dd-7ec3-4331-9865-1552d7b450bb","html_url":"https://github.com/xp-framework/test","commit_stats":{"total_commits":141,"total_committers":1,"mean_commits":141.0,"dds":0.0,"last_synced_commit":"58dda70edff4753ff23a59aa74dfdd97f19913e6"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/xp-framework/test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Ftest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Ftest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Ftest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Ftest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Ftest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28562249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T03:31:16.861Z","status":"ssl_error","status_checked_at":"2026-01-19T03:31:15.069Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["annotations","assertions","php7","php8","testcase","testing","unittest","xp-framework"],"created_at":"2024-11-19T16:48:21.559Z","updated_at":"2026-01-19T06:04:01.948Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","readme":"Tests\n=====\n\n[![Build status on GitHub](https://github.com/xp-framework/test/workflows/Tests/badge.svg)](https://github.com/xp-framework/test/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/test/version.svg)](https://packagist.org/packages/xp-framework/test)\n\nUnit and integration tests for the XP Framework\n\nWriting a test\n--------------\nTests reside inside a class suffixed by \"Test\" (*a test group*) and consist of methods annotated with the `Test` attribute (*the test cases*). The convention for test method naming is to use lowercase, words separated by underscores, though this is not strictly necessary.\n\n```php\nuse test\\{Assert, Test};\n\nclass CalculatorTest {\n\n  #[Test]\n  public function addition() {\n    Assert::equals(2, (new Calculator())-\u003eadd(1, 1));\n  }\n}\n```\n\nTo run these tests, use the `test` subcommand:\n\n```sh\n$ xp test CalculatorTest.class.php\n\u003e [PASS] CalculatorTest\n  ✓ addition\n\nTests cases: 1 succeeded, 0 skipped, 0 failed\nMemory used: 1556.36 kB (1610.49 kB peak)\nTime taken:  0.001 seconds\n```\n\nAssertions\n----------\nThe following shorthand methods exist on the `Assert` class:\n\n* `equals(mixed $expected, mixed $actual)` - check two values are equal. Uses the `util.Objects::equal()` method internally, which allows overwriting object comparison.\n* `notEquals(mixed $expected, mixed $actual)` - opposite of above\n* `true(mixed $actual)` - check a given value is equal to the *true* boolean\n* `false(mixed $actual)`  - check a given value is equal to the *false* boolean\n* `null(mixed $actual)` - check a given value is *null*\n* `instance(string|lang.Type $expected, mixed $actual)` - check a given value is an instance of the given type.\n* `matches(string $pattern, mixed $actual)` - verify the given value matches a given regular expression.\n* `throws(string|lang.Type $expected, callable $actual)` - verify the given callable raises an exception.\n\nExpected failures\n-----------------\nUsing the `Expect` annotation, we can write tests that assert a given exception is raised:\n\n```php\nuse test\\{Assert, Expect, Test};\n\nclass CalculatorTest {\n\n  #[Test, Expect(DivisionByZero::class)]\n  public function division_by_zero() {\n    (new Calculator())-\u003edivide(1, 0);\n  }\n}\n```\n\nTo check the expected exceptions' messages, use the following:\n\n* Any message: `Expect(DivisionByZero::class)`\n* Exact message: `Expect(DivisionByZero::class, 'Division by zero')`\n* Message matching regular expression: `Expect(DivisionByZero::class, '/Division by (0|zero)/i')`\n\nValue-driven tests\n------------------\nTo keep test code short and concise, tests may be value-driven. Values can be provided either directly inline:\n\n```php\nuse test\\{Assert, Test, Values};\n\nclass CalculatorTest {\n\n  #[Test, Values([[0, 0], [1, 1], [-1, 1]])]\n  public function addition($a, $b) {\n    Assert::equals($a + $b, (new Calculator())-\u003eadd($a, $b));\n  }\n}\n```\n\n...or by referencing a provider method as follows:\n\n```php\nuse test\\{Assert, Test, Values};\n\nclass CalculatorTest {\n\n  private function operands(): iterable {\n    yield [0, 0];\n    yield [1, 1];\n    yield [-1, 1];\n  }\n\n  #[Test, Values(from: 'operands')]\n  public function addition($a, $b) {\n    Assert::equals($a + $b, (new Calculator())-\u003eadd($a, $b));\n  }\n}\n```\n\nPrerequisites\n-------------\nTest classes and methods may have prerequisites, which must successfully verify in order for the tests to run:\n\n```php\nuse test\\verify\\Runtime;\nuse test\\{Assert, Test};\n\n#[Runtime(extensions: ['bcmath'])]\nclass CalculatorTest {\n\n  #[Test]\n  public function addition() {\n    Assert::equals(3, (int)bcadd(1, 2));\n  }\n}\n```\n\nThe following verifications are included:\n\n* `Runtime(os: '^WIN', php: '^8.0', extensions: ['bcmath'])` - runtime verifications.\n* `Condition(assert: 'function_exists(\"random_int\")')` - verify given expression in the context of the test class.\n\nPassing arguments to tests\n--------------------------\nEspecially for integration tests, passing values like a connection string from the command line to the test class is important. Add the `Args` annotation to the class as follows:\n\n```php\nuse test\\Args;\nuse com\\mongodb\\MongoConnection;\n\n#[Args('use')]\nclass IntegrationTest {\n  private $conn;\n\n  public function __construct(string $dsn) {\n    $this-\u003econn= new MongoConnection($dsn);\n  }\n\n  // ...shortened for brevity\n}\n```\n\n...then pass the arguments as follows:\n\n```bash\n$ xp test IntegrationTest --use=mongodb://locahost\n# ...\n```\n\nSee also\n--------\n* [RFC #344: New testing library](https://github.com/xp-framework/rfc/issues/344)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Ftest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Ftest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Ftest/lists"}