Skip to content

Commit b3b56dd

Browse files
committed
First commit
0 parents  commit b3b56dd

29 files changed

+6694
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at https://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.yml]
18+
indent_size = 2

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/tests export-ignore
11+
/.editorconfig export-ignore

.github/workflows/run-tests.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
php-tests:
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
php: [7.4, 7.3, 7.2]
15+
laravel: [6.*, 7.*]
16+
os: [ubuntu-latest]
17+
include:
18+
- laravel: 6.*
19+
testbench: 4.*
20+
- laravel: 7.*
21+
testbench: 5.*
22+
23+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v1
28+
29+
- name: Setup PHP
30+
uses: shivammathur/setup-php@v1
31+
with:
32+
php-version: ${{ matrix.php }}
33+
extension: pdo, sqlite, pdo_sqlite
34+
coverage: none
35+
36+
- name: Install dependencies
37+
run: |
38+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
39+
composer update --prefer-dist --prefer-dist --no-interaction --no-suggest
40+
41+
- name: Info
42+
run: composer show
43+
44+
- name: Execute tests
45+
run: composer test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
docs
3+
vendor
4+
coverage
5+
/.phpunit.result.cache
6+
.idea
7+
/coverage.clover
8+
/.phpcs-cache

.scrutinizer.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+

.styleci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
preset: laravel
2+
3+
disabled:
4+
- single_class_element_per_statement
5+
- self_accessor

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-e2e-routes` will be documented in this file
4+
5+
## 1.0.0 - 2020-02-11
6+
7+
- initial release

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Can Vural
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Set of routes to manage your data in E2E tests
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/canvural/laravel-e2e-routes.svg?style=flat-square)](https://packagist.org/packages/canvural/laravel-e2e-routes)
4+
![Run tests](https://github.com/canvural/laravel-e2e-routes/workflows/Run%20tests/badge.svg?branch=master)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/canvural/laravel-e2e-routes.svg?style=flat-square)](https://packagist.org/packages/canvural/laravel-e2e-routes)
6+
7+
8+
This package provides a set of rules to help you manage your database state when running your E2E tests using Eloquent model factories.
9+
## Installation
10+
11+
You can install the package via composer:
12+
13+
```bash
14+
composer require canvural/laravel-e2e-routes
15+
```
16+
17+
If you wish to customize some options, you may publish the config file with
18+
19+
```bash
20+
php artisan vendor:publish --provider="Vural\E2ERoutes\E2ERoutesServiceProvider"
21+
```
22+
23+
This is the published config files contents. Here you can customize the route prefix which will be added to all the provided routes.Route names, and the namespace that all your models live in.
24+
```php
25+
<?php
26+
27+
return [
28+
'prefix' => 'e2e',
29+
'name' => 'e2e-routes',
30+
'modelNamespace' => 'App\\',
31+
];
32+
33+
```
34+
35+
## Usage
36+
37+
For obvious reasons this package does not exposes the routes in the `production` environment. In other environments you can use the routes.
38+
39+
#### Reset database (GET `e2e/reset`)
40+
41+
You can use the `http://localhost/e2e/reset` route to reset your database. Under the hood this route makes a call to `migrate:refresh` Artisan command. Also if you wish to `seed` your database after migrating, you may call the route with `seed` query string attached. `http://localhost/e2e/reset?seed`
42+
43+
#### Creating models (POST `e2e/{modelName}`)
44+
45+
This package uses your Eloquent model factories to create the data.
46+
47+
So, for example if you have a model called `User` and the associated `UserFactory` you can make a POST request to the `http://localhost/e2e/user` endpoint to create a `User` in your database. Also, newly created model will be returned as a response from the endpoint.
48+
49+
You can substitute `user` in the above example with any model you want. If the given model is not found, a `404` response will be returned. Also, if the model exists but a factory for that model does not exists a `404` response will be returned.
50+
51+
#### Overwriting attributes
52+
53+
Like the `factory` method, this package also provides you an ability to overwrite models attributes. Simply add a body to your request like so:
54+
55+
```php
56+
[
57+
'attributes' => [ 'name' => 'John Doe' ]
58+
]
59+
```
60+
This will overwrite the `name` attribute.
61+
62+
#### Creating many models
63+
64+
You can specify how many model you want to create with
65+
```php
66+
[
67+
'times' => 3
68+
]
69+
```
70+
This will return an array containing 3 models.
71+
72+
#### Using states
73+
If you defined some states for your factories, you can use them when you are making the request.
74+
75+
```php
76+
[
77+
'states' => ['withAddress']
78+
]
79+
```
80+
This will create your model with the `withAddress` state. If the given state is not endpoint will return a `404` response.
81+
82+
#### All together
83+
```php
84+
[
85+
'attributes' => [
86+
'name' => 'John Doe',
87+
],
88+
'states' => ['withAddress'],
89+
'times' => 2
90+
]
91+
```
92+
You can also combine the options like this.
93+
94+
### Testing
95+
96+
``` bash
97+
composer test
98+
```
99+
100+
### Changelog
101+
102+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
103+
104+
## Contributing
105+
106+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
107+
108+
### Security
109+
110+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
111+
112+
## Credits
113+
114+
- [Can Vural](https://github.com/CanVural)
115+
- [All Contributors](../../contributors)
116+
117+
## License
118+
119+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

0 commit comments

Comments
 (0)