Testing!
Laravel comes with:
- PHPUnit - unit testing
- Behat - behaviour-driven development
- Mockery - mocking
- Faker - fake data
Basics
ExampleTest.php extends TestCase.php
To run:
’’’ ./vendor/bin/phpunit ‘’’
- Test names must end with Test
- Methods must start with the name test -or a @test docblock
Environment name: local,staging or production. Can be used in control structures.
.env variables come from phpunit.xml
The Testing Traits
WithoutMiddleware
-disables middleware
DatabaseMigrations
- All migrations are run for each test
DatabaseTransactions
- Use an existing DB
- Rolls back transactions after testing
Application Testing
- extend TestCase
Clicking and Forms
pg275
Mocking
Used to create a class that mimics a real class because real class is too difficult to instantiate.
What next?
Adam Wathan Laracon [https://streamacon.com/video/laracon-us/adam-wathan-test-driven-laravel]
Notes from this:
Walking Skeleton
“Programming by Wishfull Thinking”
- ModelFactories
- $user = factory(User::class)->create();
- make() not create()
- sqllite db inmemory
28:33 findByUsername - unit testing
Laracasts testing stuff