|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Alexmg86\LaravelSubQuery\Tests; |
| 4 | + |
| 5 | +use Alexmg86\LaravelSubQuery\Facades\LaravelSubQuery; |
| 6 | +use Alexmg86\LaravelSubQuery\ServiceProvider; |
| 7 | +use Alexmg86\LaravelSubQuery\Tests\Models\Invoice; |
| 8 | + |
| 9 | +class LaravelSubQuerySugarTest extends DatabaseTestCase |
| 10 | +{ |
| 11 | + protected function getPackageProviders($app) |
| 12 | + { |
| 13 | + return [ServiceProvider::class]; |
| 14 | + } |
| 15 | + |
| 16 | + protected function getPackageAliases($app) |
| 17 | + { |
| 18 | + return [ |
| 19 | + 'laravel-sub-query' => LaravelSubQuery::class, |
| 20 | + ]; |
| 21 | + } |
| 22 | + |
| 23 | + private function createBasic() |
| 24 | + { |
| 25 | + foreach (['first', 'second', 'third'] as $name) { |
| 26 | + Invoice::create(['name' => $name]); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public function testLikeLeft() |
| 31 | + { |
| 32 | + $this->createBasic(); |
| 33 | + |
| 34 | + $results = Invoice::likeLeft('name', 'st')->count(); |
| 35 | + |
| 36 | + $this->assertEquals(1, $results); |
| 37 | + } |
| 38 | + |
| 39 | + public function testLikeRight() |
| 40 | + { |
| 41 | + $this->createBasic(); |
| 42 | + |
| 43 | + $results = Invoice::likeRight('name', 'sec')->count(); |
| 44 | + |
| 45 | + $this->assertEquals(1, $results); |
| 46 | + } |
| 47 | + |
| 48 | + public function testLike() |
| 49 | + { |
| 50 | + $this->createBasic(); |
| 51 | + |
| 52 | + $results = Invoice::like('name', 'ir')->count(); |
| 53 | + |
| 54 | + $this->assertEquals(2, $results); |
| 55 | + } |
| 56 | + |
| 57 | + public function testCastColumn() |
| 58 | + { |
| 59 | + foreach (['111', '10', '2', '22'] as $name) { |
| 60 | + Invoice::create(['name' => $name]); |
| 61 | + } |
| 62 | + |
| 63 | + $results = Invoice::orderByDesc('name')->first(); |
| 64 | + |
| 65 | + $this->assertEquals(22, $results->name); |
| 66 | + |
| 67 | + $results = Invoice::castColumn('name', 'signed')->orderByDesc('name')->first(); |
| 68 | + |
| 69 | + $this->assertEquals(111, $results->name); |
| 70 | + } |
| 71 | +} |
0 commit comments