Skip to content

Commit

Permalink
Test and migration related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Jul 10, 2024
1 parent f430ce8 commit c8cb02f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
20 changes: 10 additions & 10 deletions src/Foundation/Tests/ProductSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,14 +1147,13 @@ public function it_finds_products_master_products_and_variants_where_name_begins
$resultWithVariants = (new ProductSearch())->includeVariants()->nameStartsWith('Mature')->getResults();
$this->assertCount(3, $resultWithVariants);

$first = $resultWithVariants->first();
$this->assertEquals($first instanceof MasterProductVariant ? 'Matured Wine' : 'Mature People', $first->name);

$second = $resultWithVariants->get(1);
$this->assertEquals($second instanceof MasterProduct ? 'Mature People' : 'Matured Cheese', $second->name);
$product = $resultWithVariants->first(fn ($product) => $product instanceof Product);
$master = $resultWithVariants->first(fn ($product) => $product instanceof MasterProduct);
$variant = $resultWithVariants->first(fn ($product) => $product instanceof MasterProductVariant);

$third = $resultWithVariants->last();
$this->assertEquals($third instanceof MasterProduct ? 'Mature People' : 'Matured Cheese', $third->name);
$this->assertEquals('Matured Cheese', $product->name);
$this->assertEquals('Mature People', $master->name);
$this->assertEquals('Matured Wine', $variant->name);
}

/** @test */
Expand Down Expand Up @@ -1251,9 +1250,10 @@ public function it_finds_a_variant_where_name_ends_with()
$resultWithVariants = (new ProductSearch())->includeVariants()->nameEndsWith('Transformator')->getResults();
$this->assertCount(2, $resultWithVariants);

$first = $resultWithVariants->first();
$this->assertInstanceOf(MasterProductVariant::class, $first);
$this->assertEquals('High Voltage Transformator', $first->name);
$variant = $resultWithVariants->first(fn ($product) => $product instanceof MasterProductVariant);
$this->assertNotNull($variant);
$this->assertInstanceOf(MasterProductVariant::class, $variant);
$this->assertEquals('High Voltage Transformator', $variant->name);
}

/** @test */
Expand Down
2 changes: 1 addition & 1 deletion src/Links/Tests/Feature/QueryEstablishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function models_can_be_linked_by_property_slug()
Establish::usePropertiesModel(Property::class);
Get::usePropertiesModel(Property::class);

Property::create(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'])->fresh();
Property::upsert(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'], ['slug']);
$laptop13 = TestProduct::create(['name' => 'Laptop 13"'])->fresh();
$laptop15 = TestProduct::create(['name' => 'Laptop 15"'])->fresh();
LinkType::create(['name' => 'Variant']);
Expand Down
9 changes: 6 additions & 3 deletions src/Links/Tests/Feature/QueryGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ public function the_property_filter_can_be_passed_by_slug()
{
Get::usePropertiesModel(Property::class);

$seriesProperty = Property::create(['name' => 'Series', 'slug' => 'series', 'type' => 'string'])->fresh();
$screenProperty = Property::create(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'])->fresh();
Property::upsert(['name' => 'Series', 'slug' => 'series', 'type' => 'string'], ['slug']);
$seriesProperty = Property::findBySlug('series');
Property::upsert(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'], ['slug']);
$screenProperty = Property::findBySlug('screen');
$groupSeries = LinkGroup::create(['link_type_id' => $this->variant->id, 'property_id' => $seriesProperty->id])->fresh();
$groupScreen = LinkGroup::create(['link_type_id' => $this->variant->id, 'property_id' => $screenProperty->id])->fresh();

Expand Down Expand Up @@ -245,7 +247,8 @@ public function the_links_helper_function_accepts_an_optional_property_as_second
{
Get::usePropertiesModel(Property::class);

$screenProperty = Property::create(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'])->fresh();
Property::upsert(['name' => 'Screen', 'slug' => 'screen', 'type' => 'string'], ['slug']);
$screenProperty = Property::findBySlug('screen');
$groupScreen = LinkGroup::create(['link_type_id' => $this->variant->id, 'property_id' => $screenProperty->id])->fresh();

$attrs = ['link_group_id' => $groupScreen->id, 'linkable_type' => TestLinkableProduct::class];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@ class CreatePropertiesTestTable extends Migration
{
public function up()
{
Schema::create('properties', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('type');
$table->string('slug')->nullable();
$table->json('configuration')->nullable();
$table->softDeletes();
$table->timestamps();
if (!Schema::hasTable('properties')) {
Schema::create('properties', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('type');
$table->string('slug')->nullable();
$table->json('configuration')->nullable();
$table->softDeletes();
$table->timestamps();

$table->unique('slug');
});
$table->unique('slug');
});
}
}

public function down()
{
Schema::drop('properties');
if (!Schema::hasTable('property_values')) { // this isn't present the test suite is running in standalone mode
Schema::dropIfExists('properties');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public function up(): void

public function down(): void
{
Schema::table('link_groups', function (Blueprint $table) {
$table->dropForeign('link_groups_root_item_id_foreign');
});

Schema::table('link_groups', function (Blueprint $table) {
$table->dropColumn('root_item_id');
});
Expand Down

0 comments on commit c8cb02f

Please sign in to comment.