File tree Expand file tree Collapse file tree 4 files changed +116
-0
lines changed Expand file tree Collapse file tree 4 files changed +116
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace OwenIt \Auditing \Tests \Models ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Database \Eloquent \SoftDeletes ;
7+ use OwenIt \Auditing \Contracts \Auditable ;
8+
9+ class ApiModel extends Model implements Auditable
10+ {
11+ use \OwenIt \Auditing \Auditable;
12+ use SoftDeletes;
13+
14+ /**
15+ * @var string UUID key
16+ */
17+ public $ primaryKey = 'api_model_id ' ;
18+
19+ /**
20+ * @var bool Set to false for UUID keys
21+ */
22+ public $ incrementing = false ;
23+
24+ /**
25+ * @var string Set to string for UUID keys
26+ */
27+ protected $ keyType = 'string ' ;
28+
29+ /**
30+ * {@inheritdoc}
31+ */
32+ protected $ dates = [
33+ 'published_at ' ,
34+ ];
35+
36+ /**
37+ * {@inheritdoc}
38+ */
39+ protected $ fillable = [
40+ 'api_model_id ' ,
41+ 'content ' ,
42+ 'published_at ' ,
43+ ];
44+ }
Original file line number Diff line number Diff line change 1313use OwenIt \Auditing \Models \Audit ;
1414use OwenIt \Auditing \Redactors \LeftRedactor ;
1515use OwenIt \Auditing \Redactors \RightRedactor ;
16+ use OwenIt \Auditing \Tests \Models \ApiModel ;
1617use OwenIt \Auditing \Tests \Models \Article ;
1718use OwenIt \Auditing \Tests \Models \User ;
1819use ReflectionClass ;
@@ -1100,6 +1101,24 @@ public function itTransitionsToAnotherModelState(
11001101 $ this ->assertSame ($ newExpectation , $ models [1 ]->getDirty ());
11011102 }
11021103
1104+ /**
1105+ * @test
1106+ */
1107+ public function itWorksWithStringKeyModels ()
1108+ {
1109+ $ model = factory (ApiModel::class)->create ();
1110+ $ model ->save ();
1111+ $ model ->refresh ();
1112+
1113+ $ this ->assertCount (1 , $ model ->audits );
1114+
1115+ $ model ->content = 'Something else ' ;
1116+ $ model ->save ();
1117+ $ model ->refresh ();
1118+
1119+ $ this ->assertCount (2 , $ model ->audits );
1120+ }
1121+
11031122 /**
11041123 * @return array
11051124 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Faker \Generator as Faker ;
4+ use OwenIt \Auditing \Tests \Models \ApiModel ;
5+
6+ /*
7+ |--------------------------------------------------------------------------
8+ | Article Factories
9+ |--------------------------------------------------------------------------
10+ |
11+ */
12+
13+ $ factory ->define (ApiModel::class, function (Faker $ faker ) {
14+ return [
15+ 'api_model_id ' => '8a7c2336-705a-41ad-9231-9199b4a64269 ' ,
16+ 'content ' => $ faker ->unique ()->paragraph (6 ),
17+ 'published_at ' => null ,
18+ ];
19+ });
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Illuminate \Database \Migrations \Migration ;
4+ use Illuminate \Database \Schema \Blueprint ;
5+ use Illuminate \Support \Facades \Schema ;
6+
7+ class CreateApiModelsTestTable extends Migration
8+ {
9+ /**
10+ * Run the migrations.
11+ *
12+ * @return void
13+ */
14+ public function up ()
15+ {
16+ Schema::create ('api_models ' , function (Blueprint $ table ) {
17+ $ table ->uuid ('api_model_id ' );
18+ $ table ->text ('content ' );
19+ $ table ->timestamp ('published_at ' )->nullable ();
20+ $ table ->timestamps ();
21+ $ table ->softDeletes ();
22+ });
23+ }
24+
25+ /**
26+ * Reverse the migrations.
27+ *
28+ * @return void
29+ */
30+ public function down ()
31+ {
32+ Schema::drop ('api_models ' );
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments