Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

CloudWays Blog:
Create A Laravel Vue Single Page App In Under An Hour
Feb 23, 2018 @ 10:15:51

The CloudWays blog has a new tutorial posted that walks you through the process of getting a Laravel+Vue.js single page application running in less than an hour. The instructions for the server portion cover the use of CloudWays' service but they could be applied to any number of other hosting providers.

Laravel has become the most popular choice for developing PHP projects. One important reason for this popularity is the built in support for Vue.js, a very fast growing JavaScript library for developing impressive front-ends.

This combination results is fast, secure and very impressive applications that need minimum time to go from ideation to final code review. The support for Vue.js means that Laravel developers could use Vue components easily within their apps without wasting time in writing integrations for the components. To demonstrate the support, I decided to create a single page application in Laravel with a Vue.js powered frontend.

They start off with a list of prerequisites (software to have installed) and then move on to setting up the database and creating a "tasks" migration. The tutorial then covers building out the authentication handling (via artisan) and the creation of the "task" model and controller. With all of that in place it starts in on the backend functionality to read, create, update and delete the tasks. Next it moves to the frontend showing how to create the Vue.js components required and integrating the Javascript into the view to link it to the backend for managing the tasks.

tagged: tutorial laravel singlepage application spa vuejs task

Link: https://www.cloudways.com/blog/laravel-vue-single-page-app/

Christopher Jones:
Installing XAMPP for PHP and Oracle Database
Feb 23, 2018 @ 09:47:03

On the Oracle and PHP blog today Christopher Jones has posted a tutorial showing you how to install Oracle support in PHP on a XAMPP setup. Oracle support requires the installation of the OCI8 PHP extension.

This post shows how to install XAMPP on Windows to run PHP applications that connect to a remote Oracle Database.

XAMPP is an open source package that contains Apache, PHP and many PHP 'extensions'. One of these extension is PHP OCI8 which connects to Oracle Database.

The post walks you through each of the steps required to get the combination up and running:

  • Downloading and installing XAMPP
  • Ensuring thread safety is enabled
  • Editing the php.ini to enable the OCI8 module
  • Installing the Oracle Instant Client

The post also includes some example code you can use to ensure the connection is up and working, selecting information from the default database.

tagged: oracle xampp tutorial install configure database

Link: https://blogs.oracle.com/opal/installing-xampp-for-php-and-oracle-database

Matthias Noback:
Mocking at architectural boundaries: persistence and time
Feb 22, 2018 @ 11:07:35

In a new post to his site Matthias Noback takes a look at unit testing your code and how it can be "dangerous" if you use mocking/doubles in the wrong way (not effective testing). Instead, he makes the recommendation to mock at architectural boundaries, specifically looking at mocking persistence and time handling.

More and more I've come to realize that I've been mocking less and less. The thing is, creating test doubles is a very dangerous activity.

[...] For example, by creating a test double for the EntityManager, we're assuming that it will work well with any objects we'll pass to it. If you've ever debugged an issue with an EntityManager, you know that this is a bad assumption. Anything may go wrong: a mistake in the mapping, missing configuration for cascading persist/delete behavior, an issue with the database credentials, availability of the database server, network connectivity, a missing or invalid database schema, etc.

He then gets into the concepts behind mocking across the "architecturally significant boundaries" and what kind of functionality this involves. He then gets into the two different examples sharing some of the basic concepts and test examples for evaluating persistence and time handling. He finishes up with a look at some of the potential consequences ("outcomes" is really a better word) of refactoring your tests and code to follow these ideas.

tagged: mock unittest architectural boundary persistence time tutorial

Link: https://matthiasnoback.nl/2018/02/mocking-at-architectural-boundaries-persistence-and-time/

Laravel News:
Testing Length Validation in Laravel
Feb 21, 2018 @ 09:54:40

On the Laravel News site there's a new post that gets into detail about length testing in Laravel. This testing evaluates the length of the text data taken in as input from some outside source (usually user input).

I thought it might help people new to the Laravel framework and testing, to walk through how to test length validation. When I say length validation, I mean the constraints of length that you might want to put on a string field.

[...] When testing lengths, there are a couple of techniques I think can be helpful that I use with HTTP tests to verify that my validation is working as expected. Let’s walk through some hands-on examples of the validation portion of a controller request; we will also need a test database to demonstrate a test that interacts with a database.

They start by creating a new Laravel project and adding in some basic "user" functionality to store them in a local SQLite database. It then shows the code required to validate the incoming data on the "store" method including the "max" validation handling on the email address. It then shifts over to the actual testing of the validation, writing checks to ensure the maximum length is enforced with a random string, doing the same with an email address and handling cases of multiple validation tests.

tagged: validation testing laravel tutorial maximum length

Link: https://laravel-news.com/testing-length-validation-laravel

Understanding Design Patterns - Simple Factory
Feb 19, 2018 @ 12:38:43

On the StarTutorial.com site, they've posted the latest in their article series covering design patterns and their implementation in PHP. In this latest tutorial they cover the simple factory pattern. To help illustrate the point of the pattern they use an example of a toy company with an ever-expanding line of toys.

Dragon Inc. is one of the top toy manufacturers in China. In fact, they're a pioneer in toy manufacturing. They started production at a time when few toys were being produced commercially. Hence, they dominated the market and became the leader in the toy production industry.

The initial version of their produceToy method only had to worry about toy cars and helicopters. As their line expanded, it needed to be updated for "jumping frogs" too. Adding each new toy to the single function would be difficult to maintain but the simple factory pattern came to the rescue. It allowed for the abstraction of the toy object creation out to other handling and other objects, breaking the functionality up in accordance with the Single Responsibility Principle.

tagged: tutorial designpattern simple factory series toy

Link: https://www.startutorial.com/articles/view/understanding-design-patterns-simple-factory

Laravel News:
Building a Vue SPA with Laravel Part 3
Feb 19, 2018 @ 11:22:08

The Laravel News site is back with the latest part in their series covering the combination of Laravel and Vue.js to create a basic application. In this latest part (part 3) they continue from the previous tutorials and show how to pull in real data versus the fake data from before.

We will continue building our Vue SPA with Laravel by showing you how to load asynchronous data before the vue-router enters a route.

We left off in Building a Vue SPA With Laravel Part 2 finishing a UsersIndex Vue component which loads users from an API asynchronously. We skimped on building a real API backed by the database and opted for fake data in the API response from Laravel’s factory() method.

If you haven’t read Part 1 and Part 2 of building a Vue SPA with Laravel, I suggest you start with those posts first and then come back. I’ll be waiting for you!

In this tutorial, we are also going to swap out our fake /users endpoint with a real one powered by a database.

They get immediately back to the code, creating a "user" table seeder to generate randomized data and adding it for execution. Next, they switch to the database side, creating the MySQL database for the user data and running the seeding to create the users. The tutorial then shows the creation of the Users controller and what the resulting JSON will look like when pulling all users. Finally, it moves out to the client side and shows how to pull in the data pre-load and push the user details into a template to be rendered.

tagged: vuejs spa singlepage application part3 series tutorial laravel

Link: https://laravel-news.com/building-vue-spa-laravel-part-3

Nikola Poša:
Factory as a Service
Feb 19, 2018 @ 10:53:16

In a post to his site Nikola Poša looks at a method that can be used to provide a slightly different object from a dependency injection container based on other criteria: making use of a factory as a service.

Dependency Injection Containers are a great invention - when used the right way, they allow us to keep our factories and assembly logic of services outside the core business logic of our application.

By default, a service created is shared, meaning that exactly the same instance will be returned whenever service is retrieved from a container. This is a desired behaviour in most of the cases. [...] Yet certain use cases may require services to be created conditionally during runtime, such as for example based on the value of a parameter resolved from the current request.

He first covers some of the anti-patterns that could be used to resolve this issue: a setter method on the returned object, using a service manager or creating a static factory instead. He offers a solution to the problem that makes use of a factory inside of the DI container. This factory then uses configuration values from the container to set up the object and return it.

tagged: factory service dependency injection tutorial database connection

Link: https://blog.nikolaposa.in.rs/2018/02/16/factory-as-a-service/

Alejandro Celaya:
Mutation testing with infection in big PHP projects
Feb 19, 2018 @ 09:39:58

Alejandro Celaya has a post on his site that shows how to use a less well-known testing tool - mutation testing - to test for variations on the "good" and "bad" data paths. In this article he makes use of the infection library that replaced the previously active Humbug library.

There's no doubt that having tests in a project allows you to find potential bugs earlier and more easily.

Lots of OSS projects require a minimum code coverage in order to accept new pull requests from contributors, and proprietary projects also tend to have some sort of continuous integration workflow which requires certain metrics to be fulfilled in order to get builds passing. However, the code coverage can lead to a false sense of security, which makes you think that if a certain class has a 100% code coverage, it is also 100% bug-free.

This is not always true since you could be calling a method and yet not being properly testing its output or its real behavior. The code coverage will mark it as covered, but you might introduce a bug and still have a green test. This is where mutation testing comes in.

He starts by briefly introducing the concepts of mutation testing and showing how to get the infection library installed and configured. He then gives a guide on running the tool and some of the command line options that can be used to configure threading, having it only run on covered code and setting the log verbosity. He then offers some advice on troubleshooting the use of the tool and how phpdbg is used to generate reports.

tagged: unittest mutation testing infection tutorial project

Link: https://blog.alejandrocelaya.com/2018/02/17/mutation-testing-with-infection-in-big-php-projects/

Muhammad Zamroni:
Streaming CSV Using PHP
Feb 16, 2018 @ 09:19:47

On his Medium.com site Muhammad Zamroni has a quick tutorial posted showing how to create a system that will [stream CSV data] in a Laravel application (https://medium.com/@matriphe/streaming-csv-using-php-46c717e33d87) back to the waiting client.

In one of our application, there’s a need to get list of data from a service. This data is used to generate report by background process, resulting a XLSX file that can be downloaded or attached to email. This service (an API) is written in Laravel. The background process is also written in Laravel. Both service are hosted in different server.

We pull data from MySQL and simply send the response in JSON to be easily parsed. The problem we encountered was the amount of data.

The main issue was the memory that it required to pull in all of the data and work with it. Based on some suggestions from another article they decided to switch from JSON to CSV for output and use the chunk handling to process pieces of data at a time. He includes the code for the controller that shows the use of chunk and a manual file pointer to push the data into the response 1000 records at a time.

tagged: stream csv content response laravel chunk tutorial

Link: https://medium.com/@matriphe/streaming-csv-using-php-46c717e33d87

Dries Vints:
Laravel Horizon with Forge and Envoyer
Feb 15, 2018 @ 10:53:16

Dries Vints has posted a step-by-step guide for the Laravel users out there showing how to set up Laravel Horizon using Forge and Envoyer for the server management. Laravel Horizon is a frontend/backend interface for Laravel that makes working with Redis easier.

I recently installed Horizon for Laravel.io and while it wasn’t that hard to install, I still had to figure some things out. Since this was the first time setting everything up I thought I’d write up the steps to take to get started with Horizon and set everything up with Forge and Envoyer.

[...] Remember that this isn’t a guide that dives deep into Horizon, just enough to get it up and running. If you want more info about Horizon’s internals I suggest this excellent post by Mohamed Said.

The tutorial then walks through the six step process to get the full deployment flow set up:

  • Step 1: Installation
  • Step 2: Configuration
  • Step 3: Scheduler
  • Step 4: Authentication
  • Step 5: Envoyer
  • Step 6: Forge

When the setup and configuration is complete the deployment you'll end up with a Horizon environment ready to use. The post ends with a reminder for queue management and where to change the setting to be applied in the next deploy.

tagged: laravel horizon forge envoyer deployment setup configuration tutorial

Link: https://medium.com/@driesvints/laravel-horizon-with-forge-and-envoyer-82a7e819d69f