{"id":21894761,"url":"https://github.com/zumba/elasticsearchunit","last_synced_at":"2025-04-15T16:14:50.053Z","repository":{"id":31943435,"uuid":"35513138","full_name":"zumba/elasticsearchunit","owner":"zumba","description":"Elasticsearch extension for PHPUnit.","archived":false,"fork":false,"pushed_at":"2018-12-18T15:07:36.000Z","size":53,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-03-28T22:11:20.282Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zumba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-12T21:17:18.000Z","updated_at":"2018-12-18T15:02:25.000Z","dependencies_parsed_at":"2022-08-22T21:40:12.832Z","dependency_job_id":null,"html_url":"https://github.com/zumba/elasticsearchunit","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zumba%2Felasticsearchunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zumba%2Felasticsearchunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zumba%2Felasticsearchunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zumba%2Felasticsearchunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zumba","download_url":"https://codeload.github.com/zumba/elasticsearchunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975316,"owners_count":21192209,"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":[],"created_at":"2024-11-28T13:28:01.091Z","updated_at":"2025-04-15T16:14:50.028Z","avatar_url":"https://github.com/zumba.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"ElasticSearchUnit is a PHPUnit extension for test cases that utilize the official ElasticSearch Client as their data source.\n\n[![Build Status](https://travis-ci.org/zumba/elasticsearchunit.svg)](https://travis-ci.org/zumba/elasticsearchunit)\n\n## Requirements\n\n* PHP 5.4+\n* ElasticSearch 1.7+\n\n## Testing\n\n1. Install dependencies `composer install -dev`\n2. Run `./bin/phpunit`\n\n## Example use\n\n```php\n\u003c?php\n\nclass MyElasticSearchTestCase extends \\PHPUnit_Framework_TestCase {\n\tuse \\Zumba\\PHPUnit\\Extensions\\ElasticSearch\\TestTrait;\n\n\t/**\n\t * Get the ElasticSearch connection for this test.\n\t *\n\t * @return Zumba\\PHPUnit\\Extensions\\ElasticSearch\\Client\\Connector\n\t */\n\tpublic function getElasticSearchConnector() {\n\t\tif (empty($this-\u003econnection)) {\n\t\t\t$clientBuilder = new \\Elasticsearch\\ClientBuilder();\n\t\t\t$this-\u003econnection = new \\Zumba\\PHPUnit\\Extensions\\ElasticSearch\\Client\\Connector($clientBuilder-\u003ebuild());\n\t\t}\n\t\treturn $this-\u003econnection;\n\t}\n\n\t/**\n\t * Get the dataset to be used for this test.\n\t *\n\t * @return Zumba\\PHPUnit\\Extensions\\ElasticSearch\\DataSet\\DataSet\n\t */\n\tpublic function getElasticSearchDataSet() {\n\t\t$dataset = new \\Zumba\\PHPUnit\\Extensions\\ElasticSearch\\DataSet\\DataSet($this-\u003egetElasticSearchConnector());\n\t\t$dataset-\u003esetFixture([\n\t\t\t'some_index' =\u003e [\n\t\t\t\t'some_type' =\u003e [\n\t\t\t\t\t['name' =\u003e 'Document 1'],\n\t\t\t\t\t['name' =\u003e 'Document 2']\n\t\t\t\t]\n\t\t\t]\n\t\t]);\n\t\treturn $dataset;\n\t}\n\n\tpublic function testRead() {\n\t\t$result = $this-\u003egetElasticSearchConnector()-\u003egetConnection()-\u003esearch(['index' =\u003e 'some_index']);\n\t\t$this-\u003eassertEquals(2, $result['hits']['total']);\n\t}\n\n}\n```\n\n[See full working example.](https://github.com/zumba/elasticsearchunit/blob/master/examples/PizzaTraitTest.php)\n\n## Testing with Docker/VM etc\n\nIf Elasticsearch is not running on localhost, you can provide the hostname of your Elasticsearch instance via environment variables:\n\n```bash\nES_TEST_HOST=http://docker:9200 ./bin/phpunit\n```\n\n## Elasticsearch Version Support\n\nFor Elasticsearch 5.x and greater, use version 2.x.\n\nFor Elasticsearch 2.x/1.x, use the version 1.x.\n\n## Note about PHPUnit Versions\n\nIt currently is supporting PHPUnit 4 `@before` and `@after` but can be used in PHPUnit ~3.7 by either aliasing the `elasticSearchSetUp` and `elasticSearchTearDown` to `setUp` and `tearDown`, or by calling `elasticSearchSetUp` and `elasticSearchTearDown` in your respective methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzumba%2Felasticsearchunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzumba%2Felasticsearchunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzumba%2Felasticsearchunit/lists"}