Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run phpunit with process insolation argument #4

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:

- name: Run PHPUnit tests
run: |
vendor/bin/phpunit
vendor/bin/phpunit --process-isolation
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,41 @@ class LazeTest extends \PHPUnit\Framework\TestCase {

```

## How to reset Laze during testing

If you need to reset Laze during testing, you have two options:

1. Using reflection to reset the internal state of Laze.

```php
class LazeTest extends \PHPUnit\Framework\TestCase {

public $lazeBackup;

public function setUp(): void {
parent::setUp();
$reflection = new ReflectionClass(laze::class);
$property = $reflection->getProperty('store');
$property->setAccessible(true);
$this->lazeBackup = $property->getValue();
}

public function tearDown(): void {
$reflection = new ReflectionClass(laze::class);
$property = $reflection->getProperty('store');
$property->setAccessible(true);
$property->setValue($this->lazeBackup);
parent::tearDown();
}
}
```

2. If you are using `phpunit`, then use it with the parameter `--process-isolation` to run each test in a separate process.

```bash
vendor/bin/phpunit --process-isolation
```

## Utility of this library

- **Lazy Evaluation**: Optimizes resource usage by deferring value evaluation until needed, improving performance and load times.
Expand Down