If you’re interested in the Laravel framework and possibly using it for your upcoming projects but aren’t sure where to start, you should consider checking out Matt Stauffer’s upcoming O’Reilly book "Laravel: Up and Running". According to this post on the Laravel News site the book is now available for pre-order.
Matt Stauffer has been writing a new book on Laravel named Laravel: Up and Running: A Framework for Building Modern PHP Apps and it’s published by O’Reilly Media. […] This first edition is 250 pages and will come in either paperback or ebook form, but this current preorder is only available in paperback. Based on Amazon the expected shipping date is August 25, 2016.
The book walks you through the creation of a Laravel application from start to finish. it’s no meant as a reference but a "work book" to teach the foundations of the framework. It hopes to provide a single point where developers, especially those familiar with "C-family programming languages", will be able to get started quickly.
In this new post to thePHP.cc blog Sebastian Bergmann (creator of the PHPUnit unit testing tool) questions of some the current "best practices" involved in using the tool. More specifically he looks at the handling for expected exceptions and proposes a new practice to use going forward.
It is important to keep in mind that best practices for a tool such as PHPUnit are not set in stone. They rather evolve over time and have to be adapted to changes in PHP, for instance. Recently I was involved in a discussion that questioned the current best practice for testing exceptions. That discussion resulted in changes in PHPUnit 5.2 that I would like to explain in this article.
He talks about the currently widely used practice of the
@expectedException annotation to define when an exception should be thrown from the code inside the unit test. Sebastian talks about the evolution of this into other annotations around the code and message returned from the exception too. He then proposes the new best practice as a result of some discussion around the annotation method: returning to the use of the
setExpectedException method. He provides some reasoning behind the switch including the timing of the exception being thrown (not just "any time" but a more specific time).
On the TutsPlus.com site they’ve posted a new tutorial showing you how to do test-driven development with Laravel and Doctrine, making use of Doctrine’s own testing functionality inside of a Laravel application for PHPUnit based unit testing.
As a PHP developer, you may use the Test-Driven Development (TDD) technique to develop your software by writing tests. Typically, TDD will divide each task of the development into individual units. A test is then written to ensure that the unit behaves as expected. […] TDD verifies that the code does what you expect it to do. If something goes wrong, there are only a few lines of code to recheck. Mistakes are easy to find and fix. In TDD, the test focuses on the behavior, not the implementation. TDD provides proven code that has been tested, designed, and coded.
[…] PHPUnit is the de-facto standard for unit testing PHP. It’s essentially a framework for writing tests and providing the tools that you will need to run tests and analyze the results. PHPUnit derives its structure and functionality from Kent Beck’s SUnit.
He briefly talks about some of the assertions that PHPUnit has to offer before getting into the support that Laravel includes and how to configure it so Doctrine can work with your database. He then talks about Doctrine, briefly introducing the popular database abstraction tool and how to integrate it with a Laravel application. From there he starts in on the tests themselves, showing code that uses fixture data to create several tests for Post and Comment data.
Chris Hartjes has a post on his site sharing a video from a presentation he gave about "metatesting" to a local PHP user group:
Yesterday I gave a short talk at GPUG about a topic I’ve dubbed „metatesting“. Borrowing the phrase from a children’s card game I wanted to talk about the state of testing and associated tools.
You can watch the presentation through the in-page video player including both the slides and Chris‘ presentation of them. In it he talks about mature testing tools (and extending them rather than creating new ones), open source projects and their tests or lack thereof, how testing reduces the cost of bugfixing and much more. Check out the full presentation for some great tips and updates on where software (and PHP) testing is today.
The SitePoint PHP blog has posted a tutorial continuing on from some previous advice with even more defensive programming practices you can use in your PHP applications.
Many people argue against defensive programming, but this is often because of the types of methods they have seen espoused by some as defensive programming. Defensive programming should not be viewed as a way to avoid test driven development or as a way to simply compensate for failures and move on. […] What are these methods, if not ways to anticipate that your program may fail, and either prevent those, or else ways in which to handle those failures appropriately?
They go on to talk about the ideas of "failing fast" when errors happen in your application with an extra suggestion added on – "fail loud" too. The tutorial then looks at four different places where more defensive programming techniques can be applied (and how):
- Input validation
- Preventing Accidental Assignment in Comparisons
- Dealing with Try/Catch and Exceptions
They end with a recommendation that, while you should fail fast and loud when issues come up, be sure it’s not to the determent of the overall user experience or sharing messages with users that may just confuse them.
On the Ibuildings blog Matthias Noback has kicked off a series that wants to help PHP developers reduce the complexity of their applications. In part one he shares some general tips along with code snippets illustrating the change.
PHP is pretty much a freestyle programming language. It’s dynamic and quite forgiving towards the programmer. As a PHP developer you therefore need a lot of discipline to get your code right. Over the years I’ve read many programming books and discussed code style with many fellow developers. I can’t remember which rules come from which book or person, but this article (and the following ones) reflect what I see as some of the most helpful rules for delivering better code: code that is future-proof, because it can be read and understood quite well. Fellow developers can reason about it with certainty, quickly spot problems, and easily use it in other parts of a code base.
The rest of the article is broken up into several changes you can make to reduce complex code including:
- Reduce the number of branches in a function body
- Create small logical units
- Using single (variable) types
- Making expressions more readable
He ends this first post in the series with a mention of a few other books to read up on around the subject of "clean" and less complex code.
In this post to his site Antonios Pavlakis "has a go" at creating an extension for the Behat (v3) testing tool. Behat is a testing tool written in PHP that helps with behavior-driven testing as opposed to unit testing with a tool like PHPUnit.
Ever since I got accepted to do a tutorial on Test legacy apps with Behat at the PHPNW15 conference, I’ve been meaning to look into creating custom extensions for Behat. I didn’t have enough time to research into this while preparing for the tutorial, so left it in my todo list in Trello.
During the PHPNW15 long weekend (Friday – Monday), at some point over lunch I was at the table where Matt Brunt (@themattbrunt) and Ciaran McNulty (@ciaranmcnulty) were having a conversation about this and Ciaran said (paraphrasing) “In order to be able to write an extension, you really need to understand how Behat works.”
So a few months later, sleeves up and I went into my vendor/bin/behat and started looking (and poking) around.
After looking in to two current extensions he started to get a feel for what was needed and the pieces that made up an extension. He then gets into detail on each of these pieces and shares some code/configuration he used to create the extension.
On the Zend Developer Zone blog Daniel Berman has posted a guide showing how to use their Z-Ray plugin to inspect code running on Azure for statistics around performance, queries and errors thrown by the code.
Quick experimentation, easy collaboration, automated infrastructure and scalability, together with advanced diagnostic and analytical tools – all provide PHP developers with good reasons to develop in the cloud.
[…] The combination of Z-Ray and the Azure cloud means PHP developers building apps on the Azure web app service get the best of both worlds – Z-Ray’s powerful introspection capabilities and Azure’s rich cloud infrastructure.
The post walks you through the steps to create a new Azure-based web application, how to upload your code and enable the Z-Ray feature directly from the Azure "Tools" menu. The Z-Ray toolbar is then automatically injected into your application for your immediate profiling needs.
On the NetTuts.com site there’s a tutorial posted showing you how to set up and use basic authentication in the WordPress REST API. This is part two in their series introducing the WordPress REST API.
In the introductory part of this series, we had a quick refresher on REST architecture and how it can help us create better applications. […] In the current part of the series, we will set up a basic authentication protocol on the server to send authenticated requests to perform various tasks through the REST API.
They talk about the methods that are available for authentication and how to configure your server and WordPress instance to use it. From there they show how to make authenticated requests to the API using various tools:
- the command line via curl
- using the WP HTTP API
Example code and screenshots are provided for each (where appropriate) helping to ensure you’re up and working quickly.
Michelangelo van Dam continues his series on some of the basics of PHP with another look at arrays (started in this article).
Like all things in life, we need to start with simple things. So, in order to understand what arrays are in PHP, we need to take a look at the PHP manual to read what it is all about. […] The thing with PHP is that an array is probably one of the most used data structures in web applications build with PHP and used for a wide variety of purposes.
He covers the basics of:
- storing multiple values in an array and pushing additional values onto the end
- removing the last item added to the array
- pulling the first element off of the array
In his next article, he plans on expanding this introduction to arrays by looking at associative arrays.