Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpParity\Tests;
4
5use Illuminate\Database\Schema\Blueprint;
6use Illuminate\Support\Facades\Schema;
7use Orchestra\Testbench\TestCase as Orchestra;
8use SocialDept\AtpClient\AtpClientServiceProvider;
9use SocialDept\AtpParity\ParityServiceProvider;
10use SocialDept\AtpResolver\ResolverServiceProvider;
11use SocialDept\AtpSignals\SignalServiceProvider;
12
13abstract class TestCase extends Orchestra
14{
15 protected function setUp(): void
16 {
17 parent::setUp();
18
19 $this->setUpDatabase();
20 }
21
22 protected function getPackageProviders($app): array
23 {
24 return [
25 ResolverServiceProvider::class,
26 AtpClientServiceProvider::class,
27 SignalServiceProvider::class,
28 ParityServiceProvider::class,
29 ];
30 }
31
32 protected function getEnvironmentSetUp($app): void
33 {
34 $app['config']->set('database.default', 'testing');
35 $app['config']->set('database.connections.testing', [
36 'driver' => 'sqlite',
37 'database' => ':memory:',
38 'prefix' => '',
39 ]);
40
41 $app['config']->set('parity.columns.uri', 'atp_uri');
42 $app['config']->set('parity.columns.cid', 'atp_cid');
43 }
44
45 protected function setUpDatabase(): void
46 {
47 Schema::create('test_models', function (Blueprint $table) {
48 $table->id();
49 $table->string('content')->nullable();
50 $table->string('did')->nullable();
51 $table->string('atp_uri')->nullable()->unique();
52 $table->string('atp_cid')->nullable();
53 $table->timestamp('atp_synced_at')->nullable();
54 $table->timestamps();
55 });
56
57 Schema::create('parity_import_states', function (Blueprint $table) {
58 $table->id();
59 $table->string('did');
60 $table->string('collection');
61 $table->string('status')->default('pending');
62 $table->integer('records_synced')->default(0);
63 $table->integer('records_skipped')->default(0);
64 $table->integer('records_failed')->default(0);
65 $table->string('cursor')->nullable();
66 $table->text('error')->nullable();
67 $table->timestamp('started_at')->nullable();
68 $table->timestamp('completed_at')->nullable();
69 $table->timestamps();
70
71 $table->unique(['did', 'collection']);
72 });
73
74 Schema::create('parity_conflicts', function (Blueprint $table) {
75 $table->id();
76 $table->morphs('model');
77 $table->string('uri');
78 $table->string('remote_cid');
79 $table->json('remote_data');
80 $table->string('status')->default('pending');
81 $table->timestamp('resolved_at')->nullable();
82 $table->timestamps();
83 });
84 }
85}