WooCommerce Plugin
It is an Open Source E-commerce Plugin that we can use to create a full fledged online store and customize it to our liking.
It can also integrate with payment gateways, promotions emails, tax calculations and many things.
You have to give it a try, install on local to fully know its potential, it also has REST API support so we can use it as back-end and integrate with any other front-end of our choice
Testing
Why?
Why write tests, well its a silly question to ask. We test the code we write to make sure that it works or not, if our code doesn’t work of what use it will be. Is that the only aspect of testing? to make sure it works.
Writing Tests gives us confidence in our code, we can refactor the code as much as we want and if we do something wrong tests are there to know.
How?
We can test by multiple ways, one of the most sane idea is to run the code manually and check the output if it is what we expected or not, but what if the checklist is too long, we will not be able to do it manually.
We can use tools, that test our code, we have to write the test obviously but the tools automate all the other things, like running the test, generating report, check how much code is covered by tests etc.
Unit Testing
Unit of a software is like a smallest part that can be tested, for example a function that takes some input and gives some output, it is a unit.
We run the tests against this units individually, in isolation to catch any errors early.
PHPUnit
PHP Unit is a framework for testing PHP code, basically it allows us to write code that tests our code!
To install it we can get the PHAR (PHP Archive) and make it executable
pratik@Pratiks-MacBook-Air ~ % wget -O phpunit https://phar.phpunit.de/phpunit-10.phar
chmod +x phpunit
We can also install it per project using composer
final class EmailTest extends TestCase
{
public function testCanBeCreatedFromValidEmail(): void
{
$string = 'user@example.com';
$email = Email::fromString($string);
$this->assertSame($string, $email->asString());
}
public function testCannotBeCreatedFromInvalidEmail(): void
{
$this->expectException(InvalidArgumentException::class);
Email::fromString('invalid');
}
}
Leave a Reply