Skip to content

Commit

Permalink
Add test case for wintercms/winter#1251
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Nov 18, 2024
1 parent 54a0814 commit 808fd93
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/Database/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Tests\Database;

use Mockery;
use Illuminate\Support\Facades\DB;
use Winter\Storm\Database\Model;
use Winter\Storm\Tests\DbTestCase;

class ModelTest extends \DbTestCase
class ModelTest extends DbTestCase
{
protected $seeded = [];

Expand Down Expand Up @@ -634,6 +636,19 @@ public function testUpsert()

$this->assertEquals('2', $modelMiddleRow->value);
}

public function testNicerEventOnlyBoundOnce()
{
$model = new TestModelVisibleWithEvent();
$model->name = 'Ben Thomson';
$model->save();

$this->assertEquals(1, $model->calledCount);

$model->save();

$this->assertEquals(2, $model->calledCount);

Check failure on line 650 in tests/Database/ModelTest.php

View workflow job for this annotation

GitHub Actions / ubuntu-latest / PHP 8.3

Failed asserting that 3 matches expected 2.

Check failure on line 650 in tests/Database/ModelTest.php

View workflow job for this annotation

GitHub Actions / windows-latest / PHP 8.3

Failed asserting that 3 matches expected 2.
}
}

class TestModelGuarded extends Model
Expand Down Expand Up @@ -674,6 +689,16 @@ class TestModelVisible extends Model
public $table = 'test_model';
}

class TestModelVisibleWithEvent extends TestModelVisible
{
public $calledCount = 0;

protected function afterSave()
{
$this->calledCount++;
}
}

class TestModelHidden extends Model
{
public $fillable = [
Expand Down

0 comments on commit 808fd93

Please sign in to comment.