A good store is one that not only generates profits but also lacks errors that might deter potential customers. From a developer’s perspective, the absence of errors should be one of the goals of an eCommerce store. To achieve this, developers must be confident in their code and the changes they introduce. What gives them this confidence are tests—both automated and manual. These two types differ completely in their approach. 

Automated tests, simply put, are code that tests code. These tests must be run regularly (preferably in the CI/CD process) to ensure the correctness of the changes made in the code. Manual tests, on the other hand, are performed manually by QA testers. Each type of test has its pros and cons, but one type complements the other, and their combination allows for the greatest assurance that the eCommerce application works correctly.

Sylius employs a comprehensive testing approach, including unit, integration, functional, and end-to-end tests. By utilizing tools like PHPUnit, PHPSpec, and Behat, Sylius ensures high code quality and reliability. Writing tests in Sylius adheres to best practices and enables developers to efficiently create, maintain, and develop eCommerce applications.


Quick jump


Types of tests

Software testing can be divided into different categories depending on the goal we want to achieve. The most common types are:

  • Unit Tests – Focus on testing individual units of code, such as functions or classes, in isolation from the rest of the system.
  • Integration Tests – Check if different modules of the application work together correctly.
  • Functional Tests – Verify if the application operates according to functional requirements.
  • End-to-End Tests (E2E) – Aim to verify the entire application flow from start to finish to ensure that all system components work together correctly and meet business and user requirements. For example, testing the entire flow from registration to order fulfillment.
  • Acceptance Tests – Focus on verifying whether the entire application meets business requirements and is ready for end-user use.

Advantages of writing and running tests

  • Feedback – The greatest value of automated tests is the confirmation that new changes in the code have not broken anything. The time required to get specific feedback depends on the type of test. Unit tests will be the fastest, while end-to-end tests will be the slowest due to the number of resources used and scenarios tested.
  • Early bug detection – Tests allow for quick detection of bugs in the code at an early stage of the software lifecycle, reducing costs, the time needed to fix them, and the frustration of users who encounter these bugs in the store.
  • Better code quality – Writing tests force developers to write more thoughtful and better-designed code. Code that is easy to test is also more readable and understandable.
  • Easier implementation of changes – Thanks to the feedback received from tests, developers can feel more confident when introducing new changes to the code.
  • Code documentation – Tests can serve as a form of documentation. Usage examples of functions and expected results are directly recorded in the tests, which can be helpful for new team members.

Testing tools in PHP

PHPUnit

PHPUnit is the most popular tool for unit testing in PHP. Sylius, as an application based on Symfony, fully supports PHPUnit and comes with predefined configurations for this tool.

Example of a unit test:

use PHPUnit\Framework\TestCase;
use App\Service\Calculator;

class CalculatorTest extends TestCase
{
    public function testAdd()
    {
        $calculator = new Calculator();
        $result = $calculator->add(2, 3);
        $this->assertEquals(5, $result);
    }
}

In the example above, we test the add method of the Calculator class, checking if it returns the correct result of adding two numbers.

PHPSpec

PHPSpec is a BDD (Behavior-Driven Development) style testing tool that focuses on specifying the behavior of objects. It is an ideal tool for writing unit tests in Sylius as it allows for writing tests in a way that is understandable to people.

Take a look at example specification in PHPSpec:

namespace spec\App\Service;

use App\Service\Calculator;
use PhpSpec\ObjectBehavior;

class CalculatorSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldHaveType(Calculator::class);
    }

    function it_adds_two_numbers()
    {
        $this->add(2, 3)->shouldReturn(5);
    }
}

The above specification defines the Calculator object as being able to add two numbers and return the correct result.

Behat

Behat is a BDD-based acceptance testing tool that allows for writing test scenarios in natural language (Gherkin). It is an ideal tool for testing entire business processes in Sylius.

An example scenario in Behat:

Feature: Add product to cart
  In order to buy products
  As a customer
  I need to be able to add products to my shopping cart

Scenario: Adding a product to the cart
  Given I am on the homepage
  When I add "Product A" to the cart
  Then I should see "Product A" in the cart

The above scenario defines a simple process of adding a product to the cart, which can then be implemented using Behat. To make it work, you must also create a context and suite configuration for this scenario. You can read more about Behat here:

WebTestCase

WebTestCase is an extension of PHPUnit in Symfony that allows for testing the application as a whole by simulating HTTP requests. It is particularly useful for functional tests in Sylius.

Example functional test:

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ProductControllerTest extends WebTestCase
{
    public function testShowProduct()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/product/1');
        $this->assertResponseIsSuccessful();
        $this->assertSelectorTextContains('h1', 'Product Name');
    }
}

The above functional test checks if the product page displays the correct information after loading.

Best practices for testing in Sylius

Testing projects built on Sylius requires applying best practices to ensure the efficiency and effectiveness of the testing process. Here are some key tips:

Ensure code coverage with tests
Achieving 100% test coverage is difficult or even impossible, so make sure to cover all critical parts of the application with tests. Prioritize testing business code and key functionalities.

Write readable tests
Tests should be easy to understand and maintain. Use descriptive method names and structure tests in a way that reflects the business logic of the application.

Automate Tests

Integrate tests with the CI/CD system so that they run automatically with every code change. This way, you will catch bugs before the client does in production.

Test edge cases
Testing only the successful path rarely ensures that the code works correctly. You also need to focus on edge cases. When writing cart tests, consider what happens if the user enters a negative quantity. What if they add the same product to the cart again? Remember, when writing code and tests, think outside the box because that is how the client will behave in your store.

Check what Sylius offers
Sylius has a lot of tests. Instead of reinventing the wheel, take a moment to check if a similar Behat step already exists in some Sylius context or if there is a test checking the same area of the application. If you find one, don’t be afraid to use or copy it into your test.

If possible, integrate Sylius and plugin tests into the CI/CD process
This step is often overlooked in projects, mainly due to the time required to run Behat tests and sometimes problematic fixes. However, if you have the capability and budget, this step will bring a lot of benefits to your project. With a large number of Sylius tests, you can ensure that the module or functionality you override does not break the base logic.

Role of manual testing in Sylius projects

Manual testing plays a critical role in ensuring the quality and reliability of Sylius-based eCommerce platforms, complementing automated testing strategies. Its focus is on integration tests, functional tests, and E2E tests. 

While automated tests are highly efficient for repetitive tasks and validation of predictable behaviors, manual testing addresses aspects of the system that require Sylius knowledge, human judgment, creativity, and an understanding of user needs and behavior.

Manual testing helps with areas that are hard or even impossible to cover by automated tests, such as:

  • UI/UX – manual testing means working with UI. This means that applications are used most of the time in the same way as future users. Because of that, actual UI problems can be detected and fixed (especially when Sylius is heavily customized with new code or plugins), and valuable feedback about user experience can be found.
  • Edge cases – finding edge cases is often done during manual tests when testers think like end-users and intentionally explore unconventional or extreme scenarios. Examples of such actions are entering unexpected inputs, performing actions in unusual sequences, or testing the system’s behavior under boundary conditions and high loads. Edge case finding can also be a byproduct of simply using an application and its UI during tests. Many issues remain unknown until manual tests are done. While already detected problems can be covered by automated testing, the important part here is to detect problems to prevent users from running into them. 
  • Integration – checking third-party integrations with the Sylius application is an important task. The most common example is payment gateways. It’s much simpler to just use the payment system provided by the payment gateway – usually by logging into their application – and confirming how payment flow works between Sylius and the payment gateway based on data available in that system. While automated tests can cover some base situations here, manual testing is also always present.
  • Cross-Device – it became second nature to offer a pleasurable experience with mobile versions of applications, especially in eCommerce. Mobile web traffic share keeps growing (close to 60% global already) – more and more people are using smartphones to browse the internet. Visual verification of application appearance on different screen resolutions requires the human eye in order to keep it practical, readable, and useful and to provide users with experience that won’t discourage them from using the application.

Useful manual testing tools

A lot of tools can help with manual testing. Selected applications seem to be more helpful than others when it comes to Sylius and checking its behavior due to its eCommerce nature. These useful tools can enhance testing in a meaningful way:

  • Database client software  – tools like DBeaver are irreplaceable by giving you access to the database to inspect, modify, or query data. Database changes happen all the time, and validating that actions save data in a proper table in the proper format is crucial for the application to operate correctly. Debugging some functionalities requires specific data to be used, and having access to change data directly in a database can be much faster and more convenient than trying to do that via UI.
  • Mailhog – lightweight email testing tool that captures emails sent from the application in a testing environment. In Sylius, it’s helpful in validating email notifications such as order confirmations, password reset requests, and promotional messages. Email’s content, layout, and recipient address can be verified in a simple way without actually sending messages to end-users. It is worth noting that this tool is perfect for testing in a local environment.
  • Postman – this is an API testing tool that allows us to send requests to the Sylius backend and validate the responses if there is no need to check those elements. It’s useful for testing REST APIs, verifying data returned from endpoints, and ensuring the correctness of API workflows like product creation or order management. 
  • Tampermonkey – a browser extension that enables the possibility to create and run custom user scripts, which can manipulate or automate browser behavior. For Sylius projects, it can be used to simulate user actions, test edge cases in the browser, or adjust data on the fly to validate specific scenarios without backend changes. It’s perfect for its ability to adjust to specific needs or problems. The most useful case is a script that can help you fill a form with prepared data (not a random one!) so you have complete control over the case being tested. 

Of course, tools – as important as they are – won’t change the fact that the best tool for manual testing is knowledge. Since it requires working primarily with a creative mind and imagination, a grasp of eCommerce in general and what users expect from applications that allow them to buy products is priceless. Of even greater importance is Sylius’ expertise – the most critical areas being products and their presentation, checkout processes, administration via Admin Panel, and data storage structure in the database. It is simple to look for problems if you know where to look.

Combining automated and manual testing

To achieve a robust and efficient testing process in Sylius projects, it’s crucial to combine the strengths of both manual and automated testing. Each approach has unique advantages, and by integrating these methods, teams can create a complementary testing strategy that balances coverage, adaptability, and efficiency, ensuring the final product meets both technical and user expectations.

  • The division of labor between manual and automated testing plays an important role in maximizing efficiency and coverage
    Automated tests excel at handling repetitive tasks, such as regression testing, where stable and predictable workflows need to be validated consistently across code changes. They are ideal for validating core functionalities and critical paths like checkout or payment processing. Sylius offers a lot of tests, and it saves a huge amount of human time by not repeating those core steps whenever a bigger code change happens. On the other hand, manual testing focuses on exploratory testing, where human intuition and creativity are needed to uncover hidden bugs or usability issues. It is also critical to ensure that the interface is intuitive and aligns with user expectations. This separation ensures that routine validations are automated for speed while human expertise is directed toward areas requiring deeper insight.
  • Manual testing helps in shaping test automation
    Manual tests uncover scenarios that lead to a specific problem. Some of those concerns are repetitive and can be critical to the system’s functionality. Many cases are connected to prices – and numbers in general – which is great since it is usually a perfect opportunity to implement those as automated tests. Looking at the bigger picture, not only single scenarios but whole patterns of possible user behavior could repeat. Users can be creative when it comes to – for example – data input and doing things in a simple, intuitive manner (which is not always as we have expected). It is perfect to look at those patterns – and manual test results overall – as possible guides for the development of new targeted automated test cases so issues can be prevented in the future.

Want to know more about Sylius?

sylius-logo

Wrapping up

Testing projects built on Sylius is crucial in ensuring their quality and stability. Using tools such as PHPUnit, PHPSpec, Behat, and WebTestCase allows for effective testing of various aspects of the application. Following best practices, such as covering critical parts of the application with tests, writing readable tests, and automating the testing process, contributes to creating a solid and reliable e-commerce platform.

Regular review and refactoring of tests, as well as edge case testing, help maintain high code quality as the project evolves. Manual testing complements automated processes by providing the human insight needed to deliver a seamless and reliable eCommerce experience. It is not only an additional layer for detecting problems but also an opportunity to improve user experience and quality of application.As a result of the above, projects built on Sylius can deliver business value to end users while minimizing the risk of errors and production issues.