PHPackages                             mwangaben/cypress-cypress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mwangaben/cypress-cypress

ActiveLibrary

mwangaben/cypress-cypress
=========================

Laravel Cypress Boilerplate

v1.0(5y ago)011MITPHPPHP ^7.3|^8.0

Since Jan 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/mwangaben/cypress)[ Packagist](https://packagist.org/packages/mwangaben/cypress-cypress)[ Docs](https://github.com/mwangaben/cypress-cypress)[ RSS](/packages/mwangaben-cypress-cypress/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel + Cypress Integration
=============================

[](#laravel--cypress-integration)

This package provides the necessary boilerplate to quickly begin testing your Laravel applications using Cypress.

[![](https://user-images.githubusercontent.com/183223/89684657-e2e5ef00-d8c8-11ea-825c-ed5b5acc37a4.png)](https://user-images.githubusercontent.com/183223/89684657-e2e5ef00-d8c8-11ea-825c-ed5b5acc37a4.png)

Installation
------------

[](#installation)

Begin by installing the package as a Composer development-only dependency.

```
composer require --dev laracasts/cypress
```

If you haven't yet pulled in Cypress through npm, that's your next step:

```
npm install cypress --save-dev && npx cypress open
```

Next, generate the necessary Laravel Cypress boilerplate:

```
php artisan cypress:boilerplate
```

The final step is one you'll perform regardless of whether you use this package or not. Update your `cypress.json` file with the `baseUrl` of your application.

```
{
  "baseUrl": "http://my-app.test"
}
```

When making requests in your Cypress tests, this `baseUrl` will be prepended to any relative URL you provide.

```
cy.visit('/foo'); // http://my-app.test/foo
```

Environment Handling
--------------------

[](#environment-handling)

After running the `php artisan cypress:boilerplate` command, you'll now have a `.env.cypress`file in your project root. To get you started, this file is a duplicate of `.env`. Feel free to update it as needed to prepare your application for your Cypress tests.

Likely, you'll want to use a special database to ensure that your Cypress acceptance tests are isolated from your local database.

```
DB_CONNECTION=mysql
DB_DATABASE=cypress

```

When running your Cypress tests, this package will automatically back up your primary `.env` file, and swap it out with `env.cypress`. Once complete, of course the environment files will be reset to how they originally were.

> All Cypress tests run according to the environment specified in `.env.cypress`.

Usage
-----

[](#usage)

This package will add a variety of commands to your Cypress workflow to make for a more familiar Laravel testing environment.

We allow for this by exposing a handful of Cypress-specific endpoints in your application. Don't worry: these endpoints will **never** be accessible in production.

### cy.login()

[](#cylogin)

Create a new user record matching the optional attributes provided and set it as the authenticated user for the test.

```
test('authenticated users can see the dashboard', () => {
  cy.login({ name: 'John Doe' });

  cy.visit('/dashboard').contains('Welcome Back, John Doe!');
});
```

### cy.logout()

[](#cylogout)

Log out the currently authenticated user. Equivalent to `auth()->logout()`.

```
test('once a user logs out they cannot see the dashboard', () => {
  cy.login({ name: 'John Doe' });

  cy.visit('/dashboard').contains('Welcome Back, John Doe!');

  cy.logout();

  cy.visit('/dashboard').assertRedirect('/login');
});
```

### cy.create()

[](#cycreate)

Use Laravel factories to create and persist a new Eloquent record.

```
test('it shows blog posts', () => {
  cy.create('App\\Post', { title: 'My First Post' });

  cy.visit('/posts').contains('My First Post');
});
```

Note that the `cy.create()` call above is equivalent to:

```
factory('App\Post')->create(['title' => 'My First Post']);
```

You may optionally specify the number of records you require as the second argument. If provided, the attributes can be provided as the third argument.

```
test('it shows blog posts', () => {
  cy.create('App\\Post', 3);

  //
});
```

### cy.refreshDatabase()

[](#cyrefreshdatabase)

Trigger a `migrate:refresh` on your test database. Often, you'll apply this in a `beforeEach` call to ensure that, before each new test in the file, your database is freshly migrated and cleaned up.

```
beforeEach(() => {
  cy.refreshDatabase();
});

test('it does something', () => {
  // php artisan migrate:fresh has been
  // called at this point.
});
```

### cy.seed()

[](#cyseed)

Run all database seeders, or a single class, in the current Cypress environment.

```
test('it seeds the db', () => {
  cy.seed('PlansTableSeeder');
});
```

Assuming that `APP_ENV` in your `.env.cypress` file is set to "acceptance," the call above would be equivalent to:

```
php artisan db:seed --class=PlansTableSeeder --env=acceptance
```

### cy.artisan()

[](#cyartisan)

Trigger any Artisan command under the current environment for the Cypress test. Remember to proceed options with two dashes, as usual.

```
test('it can create posts through the command line', () => {
  cy.artisan('post:make', {
    '--title': 'My First Post',
  });

  cy.visit('/posts').contains('My First Post');
});
```

This call is equivalent to:

```
php artisan post:make --title="My First Post"
```

### cy.php()

[](#cyphp)

While not exactly in the spirit of acceptance testing, this command will allow you to trigger and evaluate arbitrary PHP.

```
test('it can evaluate PHP', () => {
    cy.php(`
        App\\Plan::first();
    `).then(plan => {
        expect(plan.name).to.equal('Monthly');
    });
});
```

Be thoughtful when you reach for this command, but it might prove useful in instances where it's vital that you verify the state of the application or database in response to a certain action. It could also be used for setting up the "world" for your test. That said, a targeted database seeder - using `cy.seed()` - will typically be the better approach.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jeffrey Way](https://twitter.com/jeffrey_way)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1939d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccbda990e5435d93d7569bc8f17b0528421b13d469c0b8023b86db3bc5a1e369?d=identicon)[mwangaben](/maintainers/mwangaben)

---

Top Contributors

[![mwangaben](https://avatars.githubusercontent.com/u/17113999?v=4)](https://github.com/mwangaben "mwangaben (4 commits)")

---

Tags

laracastscypress

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mwangaben-cypress-cypress/health.svg)

```
[![Health](https://phpackages.com/badges/mwangaben-cypress-cypress/health.svg)](https://phpackages.com/packages/mwangaben-cypress-cypress)
```

###  Alternatives

[laracasts/cypress

Laravel Cypress Boilerplate

6273.2M4](/packages/laracasts-cypress)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
