Skip to content

Commit

Permalink
Added non-bigint test case for channelables
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Sep 6, 2023
1 parent cd02faf commit ce74a5d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Channel/Tests/ChannelablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Vanilo\Channel\Models\Channel;
use Vanilo\Channel\Tests\Dummies\ChannelableDummyPlan;
use Vanilo\Channel\Tests\Dummies\ChannelableDummyProduct;
use Vanilo\Channel\Tests\TestCase;

/**
Expand Down Expand Up @@ -60,4 +61,16 @@ public function one_shipment_can_belong_to_multiple_shippables()
$this->assertEquals($plan1->id, $channel->plans->first()->id);
$this->assertEquals($plan2->id, $channel->plans->last()->id);
}

/** @test */
public function channelables_work_with_older_non_bigint_id_models()
{
$product = ChannelableDummyProduct::create(['name' => 'Pro-Duct']);
$channel = Channel::create(['name' => 'B2B']);

$product->channels()->save($channel);

$this->assertCount(1, $product->channels);
$this->assertEquals($channel->id, $product->channels->first()->id);
}
}
29 changes: 29 additions & 0 deletions src/Channel/Tests/Dummies/ChannelableDummyProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

/**
* Contains the ChannelableDummyProduct class.
*
* @copyright Copyright (c) 2023 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2023-09-06
*
*/

namespace Vanilo\Channel\Tests\Dummies;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Vanilo\Channel\Models\Channel;

class ChannelableDummyProduct extends Model
{
protected $guarded = ['id'];

public function channels(): MorphToMany
{
return $this->morphToMany(Channel::class, 'channelable');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ public function up()
$table->string('name');
$table->timestamps();
});
Schema::create('channelable_dummy_products', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}

public function down()
{
Schema::drop('channelable_plans');
Schema::drop('channelable_dummy_products');
}
};

0 comments on commit ce74a5d

Please sign in to comment.