Eloquent's `is()` method
?? Use Eloquent's "->is()" method for more expressive and thorough assertions pic.twitter.com/8zx8AEm9Rw
— Caleb Porzio (@calebporzio) 22 juni 2018
Read more [twitter.com]
Posts tagged with testing
?? Use Eloquent's "->is()" method for more expressive and thorough assertions pic.twitter.com/8zx8AEm9Rw
— Caleb Porzio (@calebporzio) 22 juni 2018
Read more [twitter.com]
In an older but still relevant blogpost Matt Stauffer explains how you can extend PHPUnit's native @requires annotation. It's pretty handy if you want to only run certain tests in certain environments.
I was primarily interested in learning—how do PHPUnit annotations work? What does it look like to extend a pre-existing annotation? How do you not just check for the annotation, but also check its value? I'll show you what I found and then you can run willy-nilly with your own naming schemes.
Read more [mattstauffer.com]
Join 9,500+ smart developers
Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.
No spam. Unsubscribe anytime. You can also follow me on X.
"As a Laravel developer, this is the one newsletter I most look forward to. Freek has a talent for distilling packages or techniques down to something immediately useful - one tip can save you hours and even weeks. It's concise and practical and highly relevant."
Marcel Pociot, the mind behind BotMan, has released a cool package to create visual diff in your PHPUnit tests. Under the hood it uses our Browsershot package.
I'm not sure how you feel, but I consider myself a backend developer. Sure - I know my way around Vue.JS and really enjoy working with it, but writing CSS has never been my strong point. At one of our companies recent projects, we are working together with another development team, which is mostly taking care of frontend development. So we build controllers, repositories, services, etc. and hand it over to some basic views. They handle the rest. We introduced continuous integration to them and showed them our usual workflow, when I thought that it would be excellent to also have some kind of visual CI for frontend changes.
Read more [marcelpociot.de]
? Did you know you could use the afterCreating and lots of other "after" callbacks on Eloquent Factories to create additional models in Laravel? https://t.co/XejFph55zO #Laravel #PHP pic.twitter.com/oc8BfpEPqN
— Dries Vints (@driesvints) May 15, 2018
Read more [twitter.com]
John Bonaccorsi, a developer from Tighten, wrote some good ways of structuring model factories in a Laravel app.
Thanks to class-based model factories, our test setup went from being a bloated mess to simple and succinct. The optional fluent methods give us flexibility and make it obvious when we are intentionally changing our world. Should you read this blog post and immediately go and update all of your model factories to be class-based instead? Of course not! But if you begin to notice your tests feeling top heavy, class-based model factories may be the tool to reach for.
https://tighten.co/blog/tidy-up-your-tests-with-class-based-model-factories
? Handy lil testing macro for getting data from views pic.twitter.com/50dn2jCfSy
— Caleb Porzio (@calebporzio) March 30, 2018
Read more [twitter.com]
If you find yourself having a bunch of slow tests that don't need to execute every time you run the tests, take a look at PHPUnit's defaultTestSuite setting. TJ Miller explains it in a blog post he wrote last year.
To avoid running the interactive test suite with the rest of my tests, manually or via a CI job, I had to explicitly include all the other suites using phpunit --testsuite Api,Feature,Unit. This felt a bit grim and I would rather exclude just that one suite. So I did some digging and found the defaultTestSuite configuration for phpunit.
https://medium.com/@sixlive/separate-interactive-test-suites-f6fd59316ec2
At the assert(js) 2018 conference, Kent C. Dodds dissects this tweet by Guillermo Rauch:
Write tests. Not too many. Mostly integration.
— Guillermo Rauch (@rauchg) December 10, 2016
Frank de Jonge, creator and maintainer of Flysystem, recently started using Docker to test the FTP driver. On his blog he explains the why and how.
For Flysystem, an open source PHP package to deal with filesystems, I needed a way to test FTP (barf) interactions. FTP servers are notoriously bad at abiding by the spec. ... For Flysystem's FTP(d) adapter an integration test, using an actual FTP server, brought back the level of confidence it needed.
https://blog.frankdejonge.nl/regaining-trust-in-your-tests-with-docker/
Monica Dinculescu, an engineer at Google, shares on her blog how you can use Puppeteer, Mocha and Pixelmatch to create automated visual tests of a webpage.
I did a little song-and-dance that sets up Puppeteer* , takes screenshots of your app (like, all the routes you care about), and then compares them to the “golden” ones. If they match, your test passes! Yes, it only works on Chrome. No, it’s not actually unit testing. Yes, it’s literally just counting pixels but you know what? It counts them in both a wide and a narrow viewport size and any testing is better than no testing at all; fight me.
https://meowni.ca/posts/2017-puppeteer-tests/
I'm currently building a webapp named Oh Dear: an easy to use and beautiful website monitor. It has recently gone into it's beta phase. At the moment of writing everybody can register a new account. After you've registered you'll start your trial period of 10 days. Oh Dear is built on top Laravel…
Beautiful, organized results in PHPUnit, where have you been all my life?
— Keith Damiani (@keithdamiani) December 21, 2017
Composer-install this bad boy, add one line to phpunit.xml, and enjoy the view. ????https://t.co/JJi4tEhWWo pic.twitter.com/4pndct3iZk
Read more [twitter.com]
Laravel rockstar TJ Miller posted a short and sweet post how how he tested a middleware that forces requests to respond with JSON.
So what I’ve done here is define custom testing routes and applied the middleware as I would use it in the application routes, in this case global middleware and as middleware for the api group. This allows me to assert that the middleware is configured and functioning correctly.
https://medium.com/@sixlive/an-approach-to-testing-middleware-c547fc942848
In his excellent talk given at Laracon Online 2017, Adam Wathan argues that testing in isolation leads to brittle test and that integration tests are much more valuable.
In a fantastic post on his blog, Kent C. Dodds makes the case for focusing on writing integration tests, and stop going for 100% code coverage. Amen to that!
You may also find yourself testing implementation details just so you can make sure you get that one line of code that’s hard to reproduce in a test environment. You really want to avoid testing implementation details because it doesn’t give you very much confidence that your application is working and it slows you down when refactoring. You should very rarely have to change tests when you refactor code.
https://blog.kentcdodds.com/write-tests-not-too-many-mostly-integration-5e8c7fff591c
Need to mock a specific method in a facade, leaving the remainder free to respond to calls normally? It's possible with "Partial Mocks". pic.twitter.com/VgVMdnBDid
— Raul (@rcubitto) October 4, 2017
Read more [twitter.com]
The HTTP specification says that status codes should be three digits integers, but what happens if they are not? April King, head of website security at Mozilla, did some fun experiments to find out.
While it is easy to create test cases for conditions that don't satisfy this requirement, it is somewhat more difficult to determine how third-party libraries will handle HTTP requests that fall outside this constraint. I looked around the internet for websites to help me test weird status codes, but most of them only let me test with the known status codes. As such, I decided to add arbitrary HTTP status codes to my naughty httpbin fork, called misbehaving.site.What I discovered is that the various browser manufacturers have wildly different behavior with how they handle unknown HTTP status codes.
An official toolset for testing Vue components will be released soon. In a new series Jover Morales tells you all about it.
vue-test-utils, the official VueJS testing library and based on avoriaz, is just around the corner. @EddYerburgh is indeed doing a very good job creating it. It provides all necessary tooling for making easy to write unit test in a VueJS application.Jest, on the other side, is the testing framework developed at Facebook, which makes testing a breeze, with awesome features such as:
- Almost no config by default
- Very cool interactive mode
- Run tests in parallel
- Spies, stubs and mocks out of the box
- Built in code coverage
- Snapshot testing
- Module mocking utilities
In the JavaScript world Jest, built by Facebook, is an excellent tool to run tests. Not only can it automatically rerun your tests when source code changes, but there's also an interactive mode where you can set a filter on which tests to run while the tool is running. Would it be great if we could…
Christoper Pitt published another excellent piece over at Sitepoint. This time he describes how he built a watcher to automatically recompile his preprocessed code and rerun the tests.
In order to reduce the burden of invoking the transformation scripts, boilerplate projects have started to include scripts to automatically watch for file changes; and thereafter invoke these scripts.These projects I’ve worked on have used a similar approach to re-run unit tests. When I change the JavaScript files, these files are transformed and the unit tests are re-run. This way, I can immediately see if I’ve broken anything.
https://www.sitepoint.com/write-javascript-style-test-watchers-php/