CakeDC Blog

TIPS, INSIGHTS AND THE LATEST FROM THE EXPERTS BEHIND CAKEPHP

Best CakePHP Plugins

Members of our team had the privilege of helping with CakeFest 2020 this year. One added virtual feature was the giveaways from CakePHP, these were done in the form of fastest-to-answer, trivia, or participation (random draw). 

One of the giveaway games was to share your favorite CakePHP plugin but like, how do we only pick one, right? Anyway… There was a lot of participation in this giveaway! A few people even named our CakeDC Users plugin as their favorite *cue blushing face*. But in all seriousness, I thought it would be a good idea to share with you some of the plugins that were named most useful/helpful by CakeFest attendees this year….

 

Like I mentioned, the CakeDC users Plugin: https://github.com/CakeDC/users

Queue Plugin: https://github.com/dereuromark/cakephp-queue

Bake: https://github.com/cakephp/bake

DataTables: https://github.com/fheider/cakephp-datatables

CakePHP-tools: https://github.com/dereuromark/cakephp-tools

Authentication: https://github.com/cakephp/authentication

CakePHP-image: https://github.com/josbeir/cakephp-image

Fixturize: https://github.com/lorenzo/cakephp-fixturize

CakePHP File-Storage: https://github.com/burzum/cakephp-file-storage

Crud: https://github.com/FriendsOfCake/crud

IDE Helper: https://github.com/dereuromark/cakephp-ide-helper

Asset-Compress: https://github.com/markstory/asset_compress

CakePHP Debug Kit: https://github.com/cakephp/debug_kit

Plum-Search: https://github.com/skie/plum_search

CakePHP API: https://github.com/cakedc/cakephp-api/

Bootstrap UI: https://github.com/friendsofcake/bootstrap-ui

Trash: https://github.com/usemuffin/trash

 

You can check out the full list of CakePHP Plugins at Plugins.CakePHP.org

Have you been utilizing these tools? If not, it may be a good idea to start… while each of these serve their own purpose, using all of them can make your baking process a lot easier. 

 

Perhaps your favorite didn’t make this list? Tell us about it… email HERE. Or, tweet us @CakeDC, @CakePHP

Thanks for baking!

 

Latest articles

Window functions

This article is part of the CakeDC Advent Calendar 2025 (December 15th 2025) Did you ever wanted to provide a partial result as part of an existing report? Window functions were added in CakePHP 4.1 and provide a way to pull a rolling result expressed naturally using the ORM. We'll use CakePHP 5 code in this article. Apart from the examples described in the book https://book.cakephp.org/5/en/orm/query-builder.html#window-functions One common scenario where window functions are very useful are rolling results. Imagine we have a transactions table, where account transactions are stored including a dollar amount of the transaction. The following migration would describe an example transactions table class CreateTransactions extends \Migrations\BaseMigration { public function change(): void { $table = $this->table('transactions'); $table ->addColumn('occurred_on', 'date', [ 'null' => false, ]) ->addColumn('debit_account', 'string', [ 'limit' => 255, 'null' => false, ]) ->addColumn('credit_account', 'string', [ 'limit' => 255, 'null' => false, ]) ->addColumn('amount_cents', 'biginteger', [ 'null' => false, 'signed' => false, ]) ->addColumn('currency', 'string', [ 'limit' => 3, 'null' => false, 'default' => 'USD', ]) ->addColumn('reference', 'string', [ 'limit' => 255, 'null' => true, ]) ->addColumn('description', 'string', [ 'limit' => 255, 'null' => true, ]) ->addTimestamps('created', 'modified') ->addIndex(['occurred_on'], ['name' => 'idx_transactions_occurred_on']) ->addIndex(['debit_account'], ['name' => 'idx_transactions_debit_account']) ->addIndex(['credit_account'], ['name' => 'idx_transactions_credit_account']) ->addIndex(['reference'], ['name' => 'idx_transactions_reference']) ->create(); } } Now, let's imagine we want to build a report to render the transaction amounts, but we also want a rolling total. Using a window function, we could define a custom finder like this one: public function findWindowReport( SelectQuery $query, ?string $account, ?Date $from, ?Date $to ): SelectQuery { $q = $query ->select([ 'id', 'occurred_on', 'debit_account', 'credit_account', 'amount_cents', 'currency', 'reference', 'description', ]); // Optional filters if ($account) { $q->where(['debit_account' => $account]); } if ($from) { $q->where(['occurred_on >=' => $from]); } if ($to) { $q->where(['occurred_on <=' => $to]); } $runningWin = (new WindowExpression()) ->partition('debit_account') ->orderBy([ 'occurred_on' => 'ASC', 'id' => 'ASC' ]); $q->window('running_win', $runningWin); $q->select([ 'running_total_cents' => $q ->func()->sum('amount_cents') ->over('running_win'), ]); return $q->orderBy([ 'debit_account' => 'ASC', 'occurred_on' => 'ASC', 'id' => 'ASC' ]); } Note the WindowExpression defined will sum the amount for each debit_account to produce the running_total_cents. The result of the report, after formatting will look like this Occurred On Debit Account Credit Account Amount (USD) Running Total (USD) 1/3/25 assets:bank:checking income:services $2,095.75 $2,095.75 1/3/25 assets:bank:checking income:sales $2,241.42 $4,337.17 1/7/25 assets:bank:checking income:services $467.53 $4,804.70 1/10/25 assets:bank:checking income:subscriptions $2,973.41 $7,778.11 1/12/25 assets:bank:checking income:sales $2,747.07 $10,525.18 1/17/25 assets:bank:checking income:subscriptions $2,790.36 $13,315.54 1/21/25 assets:bank:checking income:subscriptions $1,891.35 $15,206.89 1/28/25 assets:bank:checking equity:owner $353.00 $15,559.89 Other typical applications of window functions are leaderboards (building paginated rankins with scores, sales, activities), analytics for cumulative metrics (like inventory evolution) and comparison between rows (to compute deltas) and de-duplication (to pick the most recent record for example). This is a very useful tool to provide a solution for these cases, fully integrated into the CakePHP ORM. This article is part of the CakeDC Advent Calendar 2025 (December 15th 2025)

The Generational Perception of Work and Productivity in the Remote-Work Era

Generational Work Illustration

The Generational Perception of Work and Productivity in the Remote-Work Era

In the year 2020, everything changed when the world stopped completely during COVID-19. The perception of safety, health, mental health, work, and private life completely turned around and led to a different conception of the world we knew. As the global pandemic thrived, we saw how many jobs could be done from home, because people had to reinvent themselves as we were not able to go to our workplaces. And it settled a statement, changing the perception of work dramatically. Before it, and for older generations, work was associated with physical presence, rigid schedules, and productivity measured by visible hours. But after it, younger generations saw the potential of working from home or being a so-called digital nomad, giving more priority to flexibility, emotional well-being, and measuring efficiency through results. This change reflects a social evolution guided by new technologies, new expectations, and a more connected workforce. Remote work has been key in this transformation. For thousands of professionals, the ability to work from home meant reclaiming personal time, reducing stress, and achieving a healthier work--life balance (for example, by reducing commuting time most people get almost 2 extra hours of personal time). Productivity did not decrease --- in many cases, it actually improved --- because the focus shifted from "time spent" to "goals achieved." This model has also shown that trust and autonomy can lead to more engaged teams. However, despite all of the perks, many companies are apparently eager to return to traditional workplaces. Maybe it is the fear of losing control or a lack of understanding of the new work dynamics, but this tendency threatens to undo meaningful progress for generations that have already experienced the freedom and effectiveness of remote work. Going back to the old-fashioned way of work feels like a step backward. So now, the challenge is to find a middle ground that acknowledges the cultural and technological changes of our time, passing the torch to a new generation of workers. Because productivity is no longer measured by how many people are sitting in a chair, but by the value of the final results. And if we want organizations truly prepared for the future, we must listen to younger generations and build work models that prioritize both results and workers' well-being. In CakeDC we do believe in remote work! Proving through the years that work can be done remotely no matter the timezone or language.

CakePHP E2E Testing with Cypress

End-to-End Testing CakePHP Applications with Cypress

End-to-end (E2E) testing has increasingly become a critical part of modern web development workflows. Unit and integration tests are vital, but only End-to-End (E2E) testing accurately verifies the complete user flow, from the browser interface down to the database. For robust applications built with CakePHP 5, E2E tests provide the ultimate safety net. In this article, we explore how to introduce Cypress, a popular JavaScript-based E2E testing framework, into a CakePHP 5 project. Our goal is to deliver a practical, standards-oriented approach that keeps your application maintainable, predictable, and testable at scale.

1. Why Cypress for CakePHP?

E2E testing has historically been considered slow, brittle, and difficult to maintain. Tools like Selenium or PhantomJS brought automation, but at the cost of complex setup, inconsistent execution, and poor debugging capabilities. Cypress solves many of these challenges:
  • Runs inside the browser, providing native access to DOM events
  • Offers time-travel debugging for better visibility
  • Ships with a stable execution model — no explicit waits, fewer flaky tests
  • Integrates easily with JavaScript-enabled CakePHP frontends (HTMX, Vue, React, Stimulus, etc.)
  • Provides first-class tools for network mocking, API testing, and fixtures
For CakePHP applications transitioning toward more dynamic, interactive user interfaces, Cypress becomes an essential part of the test strategy.

2. Setting up the Environment: CakePHP 5 & Cypress

Ensure you have a functioning CakePHP 5 application and Cypress installed as a development dependency: npm init -y npm install cypress --save-dev Open Cypress: npx cypress open Folder structure: cypress/ e2e/ fixtures/ support/

2.0. Understanding the Cypress Directory Structure

Running npx cypress open creates the cypress/ folder in the root of your CakePHP project. Understanding its purpose is key to organizing your tests:
Directory Purpose Relevance to CakePHP E2E
cypress/e2e Main tests. Stores all your primary test files (e.g., cart_flow.cy.js). This is where you test your CakePHP routes and UI.
cypress/fixtures Static data such as JSON files for mocking API responses. Useful for mocking external services or complex input data.
cypress/support Reusable code, custom commands, environment config, and global hooks. Crucial for defining the cy.login command using cy.session.
cypress.config.js Main Cypress configuration file. Necessary to integrate Cypress with CakePHP server and DB tasks.

2.1. The Critical E2E Test Selector: data-cy

In E2E testing, relying on standard CSS selectors like id or class is a fragile practice. Designers or frontend developers frequently change these attributes for styling or layout, which immediately breaks your tests. The best practice is to introduce a dedicated test attribute, such as data-cy. This attribute serves one purpose: E2E testing. It makes your tests resilient to UI changes. Example in a CakePHP template (.php): <button type="submit" class="btn btn-primary" data-cy="add-to-cart-button"> Add to Cart </button> Using the selector in Cypress: cy.get('[data-cy="add-to-cart-button"]').click();

3. E2E Test Case: The Shopping Cart Flow

This section details the construction of our critical E2E test, focusing on the end-user experience: Authentication, Product Addition, and Cart Verification. To ensure test reliability, we prioritize maintaining a clean and known state before execution.

3.1. Resetting the Database (beforeEach)

We must ensure a clean state for every test. Use Cypress tasks to call a CakePHP shell command that drops, migrates, and seeds your dedicated test database. // In cypress.config.js setupNodeEvents on('task', { resetDb() { console.log('Test database reset completed.'); return null; } }); // In the test file beforeEach(() => { cy.task('resetDb'); });

3.2. Shopping Cart Test (cypress/e2e/cart_flow.cy.js)

This test verifies the successful user journey from browsing to checkout initiation, using the resilient data-cy attributes. The beforeEach hook ensures that for every test, the database is reset and a user is quickly logged in via session caching. The it() Block: Core Actions and Assertions
  • Product Selection: Navigate to a specific product page. cy.visit('/products/view/1');
  • Add to Cart Action: Locate the "Add to Cart" button using data-cy and click it. cy.get('[data-cy="add-to-cart-button"]').click();
  • Confirmation Check: Assert that a visible confirmation message appears. cy.get('[data-cy="notification-message"]').should('contain', 'Product added to cart!');
  • Cart Navigation: Navigate to the cart summary page. cy.visit('/cart');
  • Content Verification (Assertions): Verify the presence of the product and the correct total price. cy.get('[data-cy="cart-item-name-1"]').should('contain', 'Product A'); cy.get('[data-cy="cart-total-price"]').should('contain', '100.00');
  • Checkout Initiation: Click the link to proceed. cy.get('[data-cy="checkout-link"]').should('be.visible').click();
  • Final Navigation Check: Assert that the URL has successfully changed to the checkout route. cy.url().should('include', '/checkout');
Test Code (cypress/e2e/cart_flow.cy.js): /// cypress/e2e/cart_flow.cy.js describe('E-commerce Shopping Cart Flow', () => { beforeEach(() => { cy.task('resetDb'); cy.login('[email protected]', 'secure-password'); }); it('Should successfully add an item to the cart and verify the total price', () => { cy.visit('/products/view/1'); cy.get('[data-cy="add-to-cart-button"]').click(); cy.get('[data-cy="notification-message"]').should('contain', 'Product added to cart!'); cy.visit('/cart'); cy.get('[data-cy="cart-item-name-1"]').should('contain', 'Product A'); cy.get('[data-cy="cart-total-price"]').should('contain', '100.00'); cy.get('[data-cy="checkout-link"]').should('be.visible').click(); cy.url().should('include', '/checkout'); }); });

4. Advanced Good Practices: Optimizing Cypress and E2E Testing

While functional E2E tests are essential, achieving a high-quality, maintainable, and fast test suite requires adopting several advanced practices.

4.1. Fast Authentication with cy.session

A standard E2E test logs in by interacting with the UI (cy.type, cy.click). While accurate, repeating this for every test is slow and inefficient. For subsequent tests in the same flow, we should skip the UI login using Cypress's cy.session. The cy.session command caches the browser session (cookies, local storage, etc.) after the first successful login. For every test that follows, Cypress restores the session state, avoiding the slow UI login process and drastically reducing execution time. Implementing the Custom cy.login Command (in cypress/support/commands.js): Cypress.Commands.add('login', (email, password) => { // 1. Define the session identifier (e.g., the user's email) const sessionName = email; // 2. Use cy.session to cache the login process cy.session(sessionName, () => { // This function only runs the first time the sessionName is encountered cy.visit('/users/login'); cy.get('[data-cy="login-email-input"]').type(email); cy.get('[data-cy="login-password-input"]').type(password); cy.get('[data-cy="login-submit-button"]').click(); // Assert that the login was successful and the session is ready cy.url().should('not.include', '/users/login'); }); // After the session is restored/created, navigate to the base URL cy.visit('/'); });

4.2. Essential Good Practices for Robust E2E Tests

Here is a list of best practices to ensure your CakePHP 5 E2E tests remain fast, stable, and easy to maintain:
  • Prioritize data-cy Selectors: As discussed, never rely on dynamic attributes like generated IDs, CSS classes (which are prone to styling changes), or nth-child selectors. Use the dedicated data-cy attribute for guaranteed stability.
  • Use Custom Commands for Repetitive Actions: Beyond login, create custom commands (e.g., cy.addItemToCart(itemId)) for any sequence of user actions repeated across multiple tests. This improves readability and reusability.
  • Avoid UI Waiting: Do not use hard-coded waiting times like cy.wait(5000). Cypress is designed to wait automatically for elements to exist and become actionable. If you need to wait for an API call, use cy.intercept() to stub or monitor network requests and then wait specifically for that request to complete (cy.wait('@api-call')).
  • Limit Scope (Test What You Own): E2E tests should focus on your application's logic, not external services (like third-party payment gateways). Use cy.stub() or cy.intercept() to mock these external interactions. If you can test a function at the unit or integration level, avoid duplicating that logic in the slower E2E layer.
  • Test Isolation is Non-Negotiable: Always use the database reset task (cy.task('resetDb')) in a beforeEach hook. Never let one test affect the state of another.
  • Break Down Large Tests: Keep individual it() blocks focused on a single logical assertion or small user journey (e.g., "Add a single item," not "Add item, change quantity, apply coupon, and checkout"). This makes debugging failure points much faster.

5. Conclusion

By combining the architectural strength of CakePHP 5 with the efficiency of Cypress, you build a highly reliable testing pipeline. Utilizing data-cy ensures your tests are stable against UI changes, and leveraging cy.session drastically reduces execution time, making E2E testing a fast and sustainable practice for your development team.

We Bake with CakePHP