Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into feat-promotion
Browse files Browse the repository at this point in the history
# Conflicts:
#	phpunit.xml.dist
  • Loading branch information
kedves committed Jul 11, 2024
2 parents f402f15 + 55fbf39 commit d222bbd
Show file tree
Hide file tree
Showing 41 changed files with 246 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build
tests/temp
/.phpunit.result.cache
/.phpunit.cache/test-results
phpunit.xml
65 changes: 65 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Contributing to Vanilo Framework

## Running Tests

By default, tests are ran against an SQLite database.

If you'd like to run against a real DB engine, the fastest way to do so is to spin up a container for the given
DB engine, and configure a local `phpunit.xml` accordingly

### MySQL 5.7

To spin up a temporary MySQL 5.7 DB use the following command:

```bash
docker run --name vanilo_test_mysql57 -e MYSQL_ROOT_PASSWORD=mypass123 -d -p 3307:3306 mysql:5.7
```

> You can choose any other container name, password or port instead of the ones in the example above
Then copy `phpunit.xml.dist` to `phpunit.xml` and add the following values before the closing `</phpunit>` tag:

```xml
<php>
<env name="APP_KEY" value="base64:gm0Aq0Xod/x8Rn2nhZLioYx55ojBcnjzaD4+GQ8M8mM="/>
<env name="APP_ENV" value="testing"/>
<env name="APP_DEBUG" value="true"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TEST_DB_ENGINE" value="mysql"/>
<env name="TEST_DB_PORT" value="3307"/>
<env name="TEST_DB_PASSWORD" value="mypass123"/>
</php>
```

### Postgres

To spin up a temporary Postgres Database use the following command:

```bash
docker run --name postgres_test -e POSTGRES_PASSWORD=pgpass123 -d -p 5452:5432 postgres
```

> You can choose any other container name, password or port instead of the ones in the example above
Then copy `phpunit.xml.dist` to `phpunit.xml` and add the following values before the closing `</phpunit>` tag:

```xml
<php>
<env name="APP_KEY" value="base64:gm0Aq0Xod/x8Rn2nhZLioYx55ojBcnjzaD4+GQ8M8mM="/>
<env name="APP_ENV" value="testing"/>
<env name="APP_DEBUG" value="true"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TEST_DB_ENGINE" value="pgsql"/>
<env name="TEST_DB_PORT" value="5452"/>
<env name="TEST_DB_PASSWORD" value="pgpass123"/>
</php>
```

2 changes: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Unreleased
##### 2024-XX-YY

- Added the `includeVariants()` method to the ProductSearch class
- Added the `includeVariants()` method to the ProductSearch class ⚠️ DOES NOT WORK ON POSTGRES (YET) ⚠️
- Added the `priceGreaterThan`, `priceLessThan` and `priceBetween` methods to the ProductSearch class by [Matima](https://github.com/mahdirezaei-dev) in [#176](https://github.com/vanilophp/framework/pull/176)
- Added the `Macroable` trait to the `ProductSearch` class
- Added the unidirectional links feature
Expand Down
111 changes: 57 additions & 54 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Contract Tests">
<directory>src/Contracts/Tests</directory>
</testsuite>
<testsuite name="Support Tests">
<directory>src/Support/Tests</directory>
</testsuite>
<testsuite name="Product Tests">
<directory>src/Product/Tests</directory>
</testsuite>
<testsuite name="Master Product Tests">
<directory>src/MasterProduct/Tests</directory>
</testsuite>
<testsuite name="Properties Tests">
<directory>src/Properties/Tests</directory>
</testsuite>
<testsuite name="Promotion Tests">
<directory>src/Promotion/Tests</directory>
</testsuite>
<testsuite name="Category Tests">
<directory>src/Category/Tests</directory>
</testsuite>
<testsuite name="Links Tests">
<directory>src/Links/Tests</directory>
</testsuite>
<testsuite name="Channel Tests">
<directory>src/Channel/Tests</directory>
</testsuite>
<testsuite name="Cart Tests">
<directory>src/Cart/Tests</directory>
</testsuite>
<testsuite name="Checkout Tests">
<directory>src/Checkout/Tests</directory>
</testsuite>
<testsuite name="Order Tests">
<directory>src/Order/Tests</directory>
</testsuite>
<testsuite name="Payment Tests">
<directory>src/Payment/Tests</directory>
</testsuite>
<testsuite name="Shipment Tests">
<directory>src/Shipment/Tests</directory>
</testsuite>
<testsuite name="Adjustments Tests">
<directory>src/Adjustments/Tests</directory>
</testsuite>
<testsuite name="Taxes Tests">
<directory>src/Taxes/Tests</directory>
</testsuite>
<testsuite name="Foundation Tests">
<directory>src/Foundation/Tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php"
backupGlobals="false" colors="true" processIsolation="false" stopOnDefect="true"
cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Contract Tests">
<directory>src/Contracts/Tests</directory>
</testsuite>
<testsuite name="Support Tests">
<directory>src/Support/Tests</directory>
</testsuite>
<testsuite name="Product Tests">
<directory>src/Product/Tests</directory>
</testsuite>
<testsuite name="Master Product Tests">
<directory>src/MasterProduct/Tests</directory>
</testsuite>
<testsuite name="Properties Tests">
<directory>src/Properties/Tests</directory>
</testsuite>
<testsuite name="Promotion Tests">
<directory>src/Promotion/Tests</directory>
</testsuite>
<testsuite name="Category Tests">
<directory>src/Category/Tests</directory>
</testsuite>
<testsuite name="Links Tests">
<directory>src/Links/Tests</directory>
</testsuite>
<testsuite name="Channel Tests">
<directory>src/Channel/Tests</directory>
</testsuite>
<testsuite name="Cart Tests">
<directory>src/Cart/Tests</directory>
</testsuite>
<testsuite name="Checkout Tests">
<directory>src/Checkout/Tests</directory>
</testsuite>
<testsuite name="Order Tests">
<directory>src/Order/Tests</directory>
</testsuite>
<testsuite name="Payment Tests">
<directory>src/Payment/Tests</directory>
</testsuite>
<testsuite name="Shipment Tests">
<directory>src/Shipment/Tests</directory>
</testsuite>
<testsuite name="Adjustments Tests">
<directory>src/Adjustments/Tests</directory>
</testsuite>
<testsuite name="Taxes Tests">
<directory>src/Taxes/Tests</directory>
</testsuite>
<testsuite name="Foundation Tests">
<directory>src/Foundation/Tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/Adjustments/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/Adjustments/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class AAASmokeTest extends TestCase
{
public const MIN_PHP_VERSION = '8.0.0';
public const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion src/Cart/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/Cart/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class AAASmokeTest extends TestCase
{
private const MIN_PHP_VERSION = '8.0.0';
private const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion src/Category/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/Category/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class AAASmokeTest extends TestCase
{
private const MIN_PHP_VERSION = '8.0.0';
private const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion src/Channel/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/Channel/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class AAASmokeTest extends TestCase
{
private const MIN_PHP_VERSION = '8.0.0';
private const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion src/Checkout/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion src/Checkout/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class AAASmokeTest extends TestCase
{
private const MIN_PHP_VERSION = '8.0.0';
private const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
php: ['8.2', '8.3']
laravel: ['10.43', '10.48', '11.0', '11.5']
laravel: ['10.43', '10.48', '11.0', '11.14']
name: PHP ${{ matrix.php }} Laravel ${{ matrix.laravel }}
steps:
- name: Checkout
Expand Down
10 changes: 9 additions & 1 deletion src/Foundation/Search/ProductSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Traits\Macroable;
use Konekt\Search\Exceptions\UnsupportedOperationException;
use Konekt\Search\Facades\Search;
use Konekt\Search\Searcher;
use Vanilo\Category\Contracts\Taxon;
Expand Down Expand Up @@ -386,7 +388,7 @@ public function getSearcher(string|array $columns = null): Searcher
return $this->searcher
->add($this->productQuery, $columns, $orderBy)
->add($this->masterProductQuery, $columns, $orderBy)
->when(null !== $this->variantQuery, fn ($search) => $search->add($this->variantQuery));
->when(null !== $this->variantQuery, fn ($search) => $search->add($this->variantQuery, $columns, $orderBy));
}

public function simplePaginate(int $perPage = 15, array $columns = ['*'], string $pageName = 'page', int $page = null): Paginator
Expand All @@ -405,8 +407,14 @@ public function getResults(int $limit = null): Collection
return is_null($limit) ? $this->getSearcher()->search() : $this->getSearcher()->simplePaginate($limit)->search()->getCollection();
}

/**
* @throws UnsupportedOperationException
*/
public function includeVariants(): self
{
if ('pgsql' === DB::connection()->getDriverName()) {
throw new UnsupportedOperationException('The `includeVariants()` feature is not supported on PostgreSQL databases.');
}
$this->variantQuery = MasterProductVariantProxy::query();

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Tests/AAASmokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class AAASmokeTest extends TestCase
{
private const MIN_PHP_VERSION = '8.0.0';
private const MIN_PHP_VERSION = '8.2.0';

/**
* @test
Expand Down
Loading

0 comments on commit d222bbd

Please sign in to comment.