diff --git a/composer.json b/composer.json index b7c1f46..ba50ec8 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,7 @@ "tipoff/support": "^1.1.2" }, "require-dev": { - "orchestra/testbench": "^6.0", - "phpunit/phpunit": "^9.3", - "spatie/laravel-ray": "^1.9", - "vimeo/psalm": "^4.4" + "tipoff/test-support": "^1.0" }, "autoload": { "psr-4": { diff --git a/database/factories/ReviewFactory.php b/database/factories/ReviewFactory.php index 5f5b60d..8081cca 100644 --- a/database/factories/ReviewFactory.php +++ b/database/factories/ReviewFactory.php @@ -33,7 +33,7 @@ public function definition() 'reviewed_at' => $this->faker->dateTimeBetween($startDate = '-7 days', $endDate = 'now', $timezone = null), 'reply' => $this->faker->sentences(3, true), 'replied_at' => $this->faker->dateTimeBetween($startDate = '-7 days', $endDate = 'now', $timezone = null), - 'location_id' => randomOrCreate(config('tipoff.model_class.location')), + 'location_id' => randomOrCreate(app('location')), ]; } } diff --git a/database/factories/SnapshotFactory.php b/database/factories/SnapshotFactory.php index 5684dc5..16da478 100644 --- a/database/factories/SnapshotFactory.php +++ b/database/factories/SnapshotFactory.php @@ -25,7 +25,7 @@ class SnapshotFactory extends Factory public function definition() { return [ - 'competitor_id' => randomOrCreate(Competitor::class), + 'competitor_id' => randomOrCreate(app('competitor')), 'date' => $this->faker->date, 'reviews' => $this->faker->numberBetween(1, 8), ]; diff --git a/src/Models/Competitor.php b/src/Models/Competitor.php index d9c93d7..0400b27 100644 --- a/src/Models/Competitor.php +++ b/src/Models/Competitor.php @@ -23,7 +23,7 @@ public function market() public function snapshots() { - return $this->hasMany(Snapshot::class); + return $this->hasMany(app('snapshot')); } public function location() @@ -38,7 +38,9 @@ public function getNameAttribute($value) public function getReviewsAttribute() { - $recent = Snapshot::where('competitor_id', $this->id)->orderByDesc('date')->first(); + $snapshot = app('snapshot'); + + $recent = $snapshot::where('competitor_id', $this->id)->orderByDesc('date')->first(); if (! isset($recent)) { return '?'; @@ -49,6 +51,8 @@ public function getReviewsAttribute() public function getWeeklyReviewsAttribute() { + $snapshot = app('snapshot'); + // Snapshots are run every Wednesday morning. $today = Carbon::now('America/New_York'); if ($today->dayOfWeek == Carbon::WEDNESDAY) { @@ -57,8 +61,8 @@ public function getWeeklyReviewsAttribute() $firstdate = new Carbon('last wednesday'); } - $recent = Snapshot::where('competitor_id', $this->id)->where('date', $firstdate->format('Y-m-d'))->first(); - $prior = Snapshot::where('competitor_id', $this->id)->where('date', $firstdate->subDays(7)->format('Y-m-d'))->first(); + $recent = $snapshot::where('competitor_id', $this->id)->where('date', $firstdate->format('Y-m-d'))->first(); + $prior = $snapshot::where('competitor_id', $this->id)->where('date', $firstdate->subDays(7)->format('Y-m-d'))->first(); if (! isset($recent) || ! isset($prior)) { return '?'; @@ -69,11 +73,13 @@ public function getWeeklyReviewsAttribute() public function getMonthlyReviewsAttribute() { + $snapshot = app('snapshot'); + // Snapshots are run on the 1st of every month. $firstdate = Carbon::now('America/New_York')->firstOfMonth(); - $recent = Snapshot::where('competitor_id', $this->id)->where('date', $firstdate->format('Y-m-d'))->first(); - $prior = Snapshot::where('competitor_id', $this->id)->where('date', $firstdate->subMonths(1)->format('Y-m-d'))->first(); + $recent = $snapshot::where('competitor_id', $this->id)->where('date', $firstdate->format('Y-m-d'))->first(); + $prior = $snapshot::where('competitor_id', $this->id)->where('date', $firstdate->subMonths(1)->format('Y-m-d'))->first(); if (! isset($recent) || ! isset($prior)) { return '?'; diff --git a/src/Models/Review.php b/src/Models/Review.php index d79a404..6774ed3 100644 --- a/src/Models/Review.php +++ b/src/Models/Review.php @@ -24,7 +24,7 @@ class Review extends BaseModel public function location() { - return $this->belongsTo(config('tipoff.model_class.location')); + return $this->belongsTo(app('location')); } public function getTitleAttribute() diff --git a/src/Models/Snapshot.php b/src/Models/Snapshot.php index 9c6c534..f8d8daf 100644 --- a/src/Models/Snapshot.php +++ b/src/Models/Snapshot.php @@ -20,6 +20,6 @@ class Snapshot extends Model public function competitor() { - return $this->belongsTo(Competitor::class); + return $this->belongsTo(app('competitor')); } }