{"id":22889611,"url":"https://github.com/dillingham/nova-assertions","last_synced_at":"2025-04-06T19:13:40.416Z","repository":{"id":40680425,"uuid":"196777272","full_name":"dillingham/nova-assertions","owner":"dillingham","description":"Laravel Nova assertions for your tests","archived":false,"fork":false,"pushed_at":"2023-09-15T10:52:55.000Z","size":87,"stargazers_count":78,"open_issues_count":10,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-30T07:45:24.575Z","etag":null,"topics":["laravel","laravel-nova","testing"],"latest_commit_sha":null,"homepage":"","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/dillingham.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","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}},"created_at":"2019-07-14T00:14:58.000Z","updated_at":"2024-06-19T09:53:49.439Z","dependencies_parsed_at":"2024-06-19T09:53:48.162Z","dependency_job_id":"96860680-8c95-4bc0-986c-a796af8e0ba5","html_url":"https://github.com/dillingham/nova-assertions","commit_stats":{"total_commits":117,"total_committers":9,"mean_commits":13.0,"dds":"0.11965811965811968","last_synced_commit":"9e6847a96db9e0f9eb5b5349c980d26df8f6cdf5"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillingham%2Fnova-assertions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillingham%2Fnova-assertions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillingham%2Fnova-assertions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dillingham%2Fnova-assertions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dillingham","download_url":"https://codeload.github.com/dillingham/nova-assertions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247535520,"owners_count":20954576,"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":["laravel","laravel-nova","testing"],"created_at":"2024-12-13T21:56:22.672Z","updated_at":"2025-04-06T19:13:40.395Z","avatar_url":"https://github.com/dillingham.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nova Assertions\n\n[![Latest Version on Github](https://img.shields.io/github/release/dillingham/nova-assertions.svg?style=flat-square)](https://packagist.org/packages/dillingham/nova-assertions)\n[![Total Downloads](https://img.shields.io/packagist/dt/dillingham/nova-assertions.svg?style=flat-square)](https://packagist.org/packages/dillingham/nova-assertions) [![Twitter Follow](https://img.shields.io/twitter/follow/im_brian_d?color=%231da1f1\u0026label=Twitter\u0026logo=%231da1f1\u0026logoColor=%231da1f1\u0026style=flat-square)](https://twitter.com/im_brian_d)\n\nNova requests \u0026 assertions for Laravel tests - [View examples](https://github.com/dillingham/nova-assertions/tree/master/examples)\n\n![testing tdd laravel nova](https://user-images.githubusercontent.com/29180903/63385407-e3f7d680-c36e-11e9-96f8-6ebbe48bd62b.png)\n\nAssert:\n[Policies](https://github.com/dillingham/nova-assertions#assert-policies) |\n[Cards](https://github.com/dillingham/nova-assertions#assert-cards) |\n[Actions](https://github.com/dillingham/nova-assertions#assert-actions) |\n[Filters](https://github.com/dillingham/nova-assertions#assert-filters) |\n[Lenses](https://github.com/dillingham/nova-assertions#assert-lenses) |\n[Resources](https://github.com/dillingham/nova-assertions#assert-resources) |\n[Fields](https://github.com/dillingham/nova-assertions#assert-fields) |\n[Relations](https://github.com/dillingham/nova-assertions#assert-relations)\n\n---\n\n### Installation\n\n```\ncomposer require dillingham/nova-assertions --dev\n```\nEnable by adding the `NovaAssertions` to a test\n```php\nuse NovaTesting\\NovaAssertions;\n\nclass UserTest extends TestCase\n{\n    use NovaAssertions;\n}\n```\n\n---\n\n### Authentication\nLog in a user that **[has access to Nova](https://nova.laravel.com/docs/2.0/installation.html#authorizing-nova)**\n```php\n$this-\u003ebe(factory(User::class)-\u003ecreate());\n```\n\n### Nova Requests\n\nRequest using a resource's uriKey to perform assertions:\n\n```php\n$response = $this-\u003enovaIndex('users');\n\n$response = $this-\u003enovaDetail('users', $user-\u003eid);\n\n$response = $this-\u003enovaCreate('users');\n\n$response = $this-\u003enovaEdit('users', $user-\u003eid);\n\n$response = $this-\u003enovaLens('users', Lens::class);\n```\n\n### Request Filters\nYou may also pass filters \u0026 their values to indexes \u0026 lenses\n```php\n$response = $this-\u003enovaIndex('users', [\n    StatusFilter::class =\u003e 'active'\n]);\n```\n```php\n$response = $this-\u003enovaLens('users', Lens::class, [\n    StatusFilter::class =\u003e 'active'\n]);\n```\n### Assert Http\nYou can call **[http response methods](https://laravel.com/docs/5.8/http-tests#available-assertions)** as usual:\n\n```php\n$response-\u003eassertOk();\n```\n### Assert Resources\n```php\n$response-\u003eassertResourceCount(3);\n```\n```php\n$response-\u003eassertResources(function($resources) {\n    return $resources-\u003ecount() \u003e 0;\n});\n```\n\n### Assert Cards\n```php\n$response-\u003eassertCardCount(5);\n```\n```php\n$response-\u003eassertCardsInclude(Card::class);\n```\n```php\n$response-\u003eassertCardsExclude(Card::class);\n```\n```php\n$response-\u003eassertCards(function($cards) {\n    return $cards-\u003ecount() \u003e 0;\n});\n```\n\n### Assert Actions\n```php\n$response-\u003eassertActionCount(5);\n```\n```php\n$response-\u003eassertActionsInclude(Action::class);\n```\n```php\n$response-\u003eassertActionsExclude(Action::class);\n```\n```php\n$response-\u003eassertActions(function($actions) {\n    return $actions-\u003ecount() \u003e 0;\n});\n```\n### Assert Filters\n```php\n$response-\u003eassertFilterCount(5);\n```\n```php\n$response-\u003eassertFiltersInclude(Filter::class);\n```\n```php\n$response-\u003eassertFiltersExclude(Filter::class);\n```\n```php\n$response-\u003eassertFilters(function($filters) {\n    return $filters-\u003ecount() \u003e 0;\n});\n```\n### Assert Lenses\n```php\n$response-\u003eassertLensCount(5);\n```\n```php\n$response-\u003eassertLensesInclude(Lens::class);\n```\n```php\n$response-\u003eassertLensesExclude(Lens::class);\n```\n```php\n$response-\u003eassertLenses(function($lenses) {\n    return $lenses-\u003ecount() \u003e 0;\n});\n```\n### Assert Fields\n```php\n$response-\u003eassertFieldCount(5);\n```\nAssert a specific field exists\n```php\n$response-\u003eassertFieldsInclude('id');\n```\nAssert a specific field contains a value\n```php\n$response-\u003eassertFieldsInclude('id', $user-\u003eid);\n```\nAssert multiple fields exist\n```php\n$response-\u003eassertFieldsInclude(['id', 'email']);\n```\nAssert multiple fields with specific values exist\n```php\n$response-\u003eassertFieldsInclude(['id' =\u003e 1, 'email' =\u003e 'example']);\n```\nAssert multiple values for one field exist\n```php\n$response-\u003eassertFieldsInclude('id', $users-\u003epluck('id'));\n```\nMake assertions against a collection of fields\n```php\n$response-\u003eassertFields(function($fields) {\n    return $fields-\u003ecount() \u003e 0;\n});\n```\nAlso `exclude` works in all of these scenarios\n```php\n$response-\u003eassertFieldsExclude(['id' =\u003e 1, 'email' =\u003e 'example']);\n```\n### Assert Relations\n```php\n// App\\Nova\\Post\n// BelongsTo::make('Category'),\n```\n```php\n$response = $this-\u003enovaCreate('posts');\n\n$response-\u003eassertRelation('categories', function($categories) {\n    //\n});\n```\n```php\n// App\\Nova\\Category\n// HasMany::make('Posts'),\n```\n```php\n$response = $this-\u003enovaDetail('categories');\n\n$response-\u003eassertRelation('posts', function($posts) {\n    //\n});\n```\n\n### Assert Policies\n\nAssert **[Nova's use of policies](https://nova.laravel.com/docs/2.0/resources/authorization.html#authorization)** \u0026 the authed user:\n\n```php\n$response-\u003eassertCanView();\n\n$response-\u003eassertCanCreate();\n\n$response-\u003eassertCanUpdate();\n\n$response-\u003eassertCanDelete();\n\n$response-\u003eassertCanForceDelete();\n\n$response-\u003eassertCanRestore();\n```\nAlso can assert `cannot` for each:\n```php\n$response-\u003eassertCannotView();\n```\n\n\n---\n\n# Author\n\nHi 👋, Im Brian Dillingham, creator of this Nova package [and others](https://novapackages.com/collaborators/dillingham)\n\nHope you find it useful. Feel free to reach out with feedback.\n\nFollow me on twitter: [@im_brian_d](https://twitter.com/im_brian_d) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillingham%2Fnova-assertions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdillingham%2Fnova-assertions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdillingham%2Fnova-assertions/lists"}