Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ylsideas/laravel-additions
Developer tools and customisations for Laravel Applications
https://github.com/ylsideas/laravel-additions
Last synced: 13 days ago
JSON representation
Developer tools and customisations for Laravel Applications
- Host: GitHub
- URL: https://github.com/ylsideas/laravel-additions
- Owner: ylsideas
- License: mit
- Created: 2020-04-22T20:09:26.000Z (almost 5 years ago)
- Default Branch: stable
- Last Pushed: 2020-05-09T18:50:25.000Z (over 4 years ago)
- Last Synced: 2024-11-13T17:30:08.035Z (2 months ago)
- Language: PHP
- Size: 69.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Additions
[![Latest Version on Packagist](https://img.shields.io/packagist/v/ylsideas/laravel-additions.svg?style=flat-square)](https://packagist.org/packages/ylsideas/laravel-additions)
[![Build Status](https://img.shields.io/travis/ylsideas/laravel-additions/master.svg?style=flat-square)](https://travis-ci.org/ylsideas/laravel-additions)
[![Quality Score](https://img.shields.io/scrutinizer/g/ylsideas/laravel-additions.svg?style=flat-square)](https://scrutinizer-ci.com/g/ylsideas/laravel-additions)
[![Total Downloads](https://img.shields.io/packagist/dt/ylsideas/laravel-additions.svg?style=flat-square)](https://packagist.org/packages/ylsideas/laravel-additions)A package of developer tools and tweaks that can be used with Laravel 7.
## Installation
You can install the package via composer:
``` bash
composer require --dev ylsideas/laravel-additions
```## Why?
I found myself doing common things in projects or just wanting a few of my custom choices
in the development product.## Usage
### Quick install for Macros and Helper files.
The following command can be used to create new php files for helpers and macros.
These files will be added to the composer.json file and the `composer dumpautoload` command
will be ran afterwards.``` bash
php artisan configure --macros --helpers
```### Publish Stubs
This library adds additional stubs over the defaults in Laravel 7 as of 19/4/20. Such additions
are notifications and events stubs.You can set the stubs directory of where to publish the stub using the app.php config.
```php
'stub_path' => resource_path(),
```Running `php artisan stub:publish` will place the stubs in the `resources/stubs/` path. There
you can edit the stubs that will be used for making new classes.### Testing Trait Hooks
Often you might want to use traits with tests to work with certain aspects. You
can now use traits with annotations `@afterAppCreated` and `@beforeAppDestroyed` which
hooks into the feature tests and calls the methods specified making it easy to switch
functionality in and out for tests.For example, you could create the trait:
```php
trait WithSomething
{
use \YlsIdeas\LaravelAdditions\Testing\WithApplicationTraitHooks;protected $user;
/**
* @afterAppCreated
*/
public function createUser()
{
$this->user = factory(User::class)->create();
}
public function actingByDefault()
{
return $this->actingAs($this->user);
}
}
```Then in your test you can apply the trait knowing the `@afterAppCreated` annotation
will be executed providing a new user allowing you to reject some boiler plate.```php
class SomethingTest extends \Tests\TestCase
{
use WithSomething;
public function testSomething()
{
$this->actingByDefault()
->get('/home')
->assertOk();
}
}
```In fact a trait that works like this already exists in this set of tools, the `WithUserAuthentication`
trait. Even tests in this package use these annotations to run setups of the test.### Setup command & Testing hooks
You can create a simple function to set up an application. This is useful if you want to be able to run
multiple commands and other tasks. There is also an initial flag which can be used to denote the application
is being set up for the first time. This command is designed to be used for local development. To make the setup
command you should do the following:```shell script
php artisan configure --hooks
```This will create a `LaravelAdditionsServerProvider` in your application's Providers folder. You can then customise the
setup hooks as well as the before and after test hook which will fire when you use the `php artisan test` command.
The default hooks look like the following:```php
class LaravelAdditionsServiceProvider extends LaravelAdditionsHooksServiceProvider
{
public function onSetup(bool $initial, Command $command) {
$command->call('migrate:fresh', ['--seed' => true]);return true;
}public function beforeTesting(InputInterface $input, OutputInterface $output) {
$output->writeln('Starting...');
}public function afterTesting(bool $passed, InputInterface $input, OutputInterface $output) {
$output->writeln('Complete!');
}
}
```### Test views generated by Mailable/Notification assertions
When testing a Mailable or Notification has been sent, the rendered view can have assertions made via a factory class
which will build a callable to detect the email type, render it into HTML and then provide a ViewAssertion instance
that you can perform assertions on.```php
class TestCase {
public function testMailable()
{
Mail::fake();
$mailable = new MailType();
$mailable->send();
Mail::assertSent(MailableType::class, MailViewAssertion::make(function (ViewAssertion $assertion) {
$assertion->contains('Hello World!');
}));
}public function testMailable()
{
Notification::fake();
$notification = new ExampleNotification();
$user->notify($notification);
Notification::assertSentTo(
$user,
ExampleNotification::class,
MailViewAssertion::make(function (ViewAssertion $assertion) {
$assertion->contains('Hello World!');
})
);
}}
```
## Testing
``` bash
composer test
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
### Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Peter Fox](https://github.com/peterfox)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
## Laravel Package Boilerplate
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).