Build A Laravel App With TDD

0
Language

Level

Beginner

Access

Paid

Certificate

Paid

It’s time to take the techniques we learned in Laravel From Scratch, and put them to good use building your first real-world application. Together, we’ll leverage TDD to create Birdboard: a minimal Basecamp-like project management app.

This series will give us a wide range of opportunities to pull up our sleeves and test our Laravel chops. As always, we start from scratch.

Add your review

Meet Birdboard

Let’s begin by reviewing the application that we plan to build. We’ll then finish up by installing Laravel and performing the first commit.

Let’s Begin With a Test

My hope is to demonstrate, as much as possible, my actual workflow when writing my own applications. With that in mind, let’s begin with our first feature test.

Testing Request Validation

We haven’t yet written any request validation logic. As before, let’s use a TDD approach for specifying each validation requirement.

Model Tests

We must next ensure that a user can visit any project page. Though we should start with a feature test, this episode will provide a nice opportunity to pause and drop down a level to a model test.

A Project Requires An Owner

It’s true that we can now create and persist projects to the database, but they aren’t currently associated with any user. This isn’t practical. To fix this, we’ll write a test to confirm that the authenticated user is always assigned as the owner of any new project that is created during their session.

Scoping Projects

In this episode, we’ll continue tweaking which projects are displayed to the user. We’ll also begin implementing the appropriate page authorization.

The Create Project View

We already have the necessary logic to persist new projects, however, we haven’t yet created the “create project” page, itself. Let’s take care of that quickly in this episode.

Prepping the Frontend

Before I begin writing CSS, we first need to set the stage. We’ll begin by pulling in all necessary npm dependencies and configuring Tailwind compilation with Laravel Mix.

Go Go Gadget Tailwind

In this episode, we’ll leverage Tailwind to begin constructing the Birdboard UI.

Grid Spacing and Card Tweaks

Let’s continue working on the CSS for the projects dashboard. This will give us an opportunity to discuss grid spacing, and how we can use a combination of padding and negative margins to perfectly align our columns.

Styling the Project Page

Before we jump back to PHP, let’s write one more lesson’s worth of CSS. Specifically, we’ll get the single project page up and running.

A Project Can Have Tasks

We’ve added a section to our project page for tasks, but that functionality doesn’t yet exist. It sounds like we have our next step.

Task UI Updates

The next step is to update your project page UI to allow for displaying and adding new tasks.

Task UI Updates: Part 2

In this episode, we’ll wrap every task within a form so that we may easily update its description or completion status with the click of a button.

Touch It

I’d like to sort all projects in our dashboard according to those that have been most recently updated. This means, when you add or modify a task within a project, we need to touch the parent project’s updated_at timestamp in the process. Let’s learn how in this episode.

Notes and Policies

Next up, we need to make the “General Notes” section of the project page dynamic. As always, we’ll use tests to drive this new update. When finished, we’ll also switch over to using dedicated authorization policy classes.

Improve Test Arrangements With Factory Classes

Let’s take a moment to improve the structure of our tests. Have you noticed that, time and time again, we follow a similar pattern when arranging the world for a test? Instead, let’s refactor this code into a fluent factory class to save time. To do this, we’ll use a technique that I first learned from John Bonaccorsi in his Tidy up Your Tests with Class-Based Model Factories article. I encourage you to give it a read if you’d like to learn more.

Reduce Form Duplication

In this lesson, we’ll add a form to update an existing project. But in the process, we’ll review how to reduce duplication in the create and edit views by extracting a reusable partial.

Sometimes Validation With Form Requests

We’ll begin this episode by addressing a small regression that was introduced in the previous episode: we can no longer update the general notes without triggering a validation error. While of course we’ll review the easy solution to this issue, we’ll additionally discuss a recent user comment related to the pros and cons of extracting a form request class. Would it make the code cleaner or better? You can look forward to lots of fun tips in this episode.

Project Activity Feeds

Let’s move on to our next feature: every project generates an activity feed.

Project Activity Feeds: Part 2

Let’s continue working on the project activity feature. We should additionally record activity when a task is created or completed. Let’s take care of that in this episode.

Project Activity Feeds: Part 3

Before moving on to the larger activity feed refactor, let’s first make a few small tweaks to clean things up.

Project Activity Feeds: Cleanup

We have just a few loose ends to wrap up, before finally viewing the project’s activity feed in the browser.

Rendering Activity With Polymorphism

It’s time to render a project’s activity feed on the page. This will give us an opportunity to review how to use polymorphism to load the appropriate view, based on the description type of the activity.

The Subject of the Activity

Now that we’re successfully displaying a project’s activity feed on the page, I’d like to provide more information for each update. For example, rather than the message, “You completed a task”, it should probably include the name of the task: ‘You completed “Finish Lesson”‘. This presents a problem because, when we record activity, we don’t yet include any reference to the subject. Let’s fix that in this episode.

Recording Model Changes

Our next job is to track which attributes have changed when a model is updated. This will allow us to record, for example, that the user changed the title of the project from “Test Project” to “Real Project”.

Get Into The Refactor Flow

In this episode, we’ll refactor all “activity” functionality to a reusable trait. As you’ll see, we’ll quickly fall into a rapid refactor flow: make a small tweak, run the tests, see green, make another small tweak, rinse and repeat.

Tweaking the Activity Card

Let’s work on tweaking the output of the activity card in this lesson. I’d like it to show which fields were updated, and who performed the update.

Authorized Users Can Delete Projects

We have an easy one this episode: users who have the proper permissions may delete or archive projects. Let’s knock that out now, before moving on to something more exciting in the next episode.

Layered Tests and Invitations

As we move on to inviting users to projects, this will give us a nice opportunity to discuss layered tests. In this episode, we’ll write the same test name at two different levels: from the outside-in (feature), and at a lower level (unit).

Beware False Positives

In this episode, as we work to allow users to see all projects they’ve been invited to from their dashboard, we’ll also discuss false positives. A passing test doesn’t always guarantee that your code works as expected.

Gravatars and Helper Functions

Our project page doesn’t yet display all members who have access to it. Let’s use Gravatar to generate these thumbnails. In doing so, this will give us the opportunity to discuss how to create and load a helper functions file.

Inviting Users as a Feature Test

In this episode, we’ll write a few new feature tests to confirm the conditions under which a project owner may invite a user to a project.

Validation Errors For Multiple Forms

Once you add multiple forms to a page, you’ll quickly find that you can no longer depend on the default validation errors “bag.” In this episode, we’ll learn how to associate your form request class with a named error bag.

Invited Users May Not Delete Projects

It looks like we have a small hiccup. At the moment, any invited user has permission to delete the project entirely. This action should be restricted to the owner of the project exclusively.

Easy Tailwind Themes Using CSS Variables

We have a relatively nice light theme at the moment. But what if we wanted to offer users the ability to toggle to a darker UI theme? How exactly might we accomplish that, considering that Tailwind classes like text-grey and text-blue are scattered throughout our HTML? The answer is to leverage CSS variables. I’ll show you how in this episode.

Completed Themes Review

Behind the scenes, I’ve finished up our two themes. Before moving on to building the theme switcher, very quickly, let’s review the results as well as the organizational structure I opted for.

Build a Theme Switcher

Now that we have multiple UI themes available to us, the next step is to construct a theme switcher that we’ll position in the navigation bar of our site. Because there’s behavior associated with each theme button, we’ll use Vue to build this little component.

The New Project Modal

Because we’re approaching the end of this series, let’s dedicate a few episodes to reviewing some JavaScript-specific enhancements. Specifically, we’ll transition the “New Project” form into a dynamic modal Vue component.

The New Project Modal: Behavior

Now that the basic styling for the “New Project” modal is complete, we can move on to its behavior. Luckily, because we have Vue backing us up each step of the way, this should be a cinch to complete.

The New Project Modal: Tasks

There’s one final step to complete: our controller doesn’t yet allow tasks to be created alongside the project. Let’s fix that now.

Object-Oriented JavaScript

If we take another look at our NewProjectModal file, you’ll notice that most of the JavaScript deals with the submission and handling of the form. It sure would be a shame to repeat this same generic code for every form in our application. With that in mind, let’s extract a BirdboardForm class to help clean things up a bit.

Make a Dropdown Vue Component

Let’s wrap things up by creating a reusable dropdown Vue component from scratch.

Wrap it Up

A series like this could go on for hundreds of hours, but, at some point, we have to wrap things up. That time is now. Let’s do one final review of what we accomplished before saying our goodbyes!

User Reviews

0.0 out of 5
0
0
0
0
0
Write a review

There are no reviews yet.

Be the first to review “Build A Laravel App With TDD”

×

    Your Email (required)

    Report this page
    Build A Laravel App With TDD
    Build A Laravel App With TDD
    LiveTalent.org
    Logo
    LiveTalent.org
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.