1+ <?php namespace Eloquent ;
2+
3+ use BaseTestCase ;
4+ use Grimzy \LaravelSpatial \Eloquent \Builder ;
5+ use Grimzy \LaravelSpatial \Eloquent \SpatialTrait ;
6+ use Grimzy \LaravelSpatial \MysqlConnection ;
7+ use Grimzy \LaravelSpatial \Types \LineString ;
8+ use Grimzy \LaravelSpatial \Types \Point ;
9+ use Grimzy \LaravelSpatial \Types \Polygon ;
10+ use Illuminate \Database \Eloquent \Model ;
11+ use Illuminate \Database \Query \Builder as QueryBuilder ;
12+ use Illuminate \Database \Query \Expression ;
13+ use Mockery ;
14+
15+ class BuilderTest extends BaseTestCase
16+ {
17+ protected $ builder ;
18+
19+ /**
20+ * @var \Mockery\MockInterface $queryBuilder
21+ */
22+ protected $ queryBuilder ;
23+
24+ protected function setUp ()
25+ {
26+ $ connection = Mockery::mock (MysqlConnection::class)->makePartial ();
27+ $ this ->queryBuilder = Mockery::mock (QueryBuilder::class, [$ connection ])->makePartial ();
28+
29+ $ this ->queryBuilder
30+ ->shouldReceive ('from ' )
31+ ->andReturn ($ this ->queryBuilder );
32+
33+ $ this ->queryBuilder
34+ ->shouldReceive ('take ' )
35+ ->with (1 )
36+ ->andReturn ($ this ->queryBuilder );
37+
38+ $ this ->queryBuilder
39+ ->shouldReceive ('get ' )
40+ ->andReturn ([]);
41+
42+ $ this ->builder = new Builder ($ this ->queryBuilder );
43+ $ this ->builder ->setModel (new TestBuilderModel ());
44+ }
45+
46+ public function testUpdate ()
47+ {
48+ $ this ->queryBuilder
49+ ->shouldReceive ('raw ' )
50+ ->with ("ST_GeomFromText('POINT(2 1)') " )
51+ ->andReturn (new Expression ("ST_GeomFromText('POINT(2 1)') " ));
52+
53+ $ this ->queryBuilder
54+ ->shouldReceive ('update ' );
55+
56+ $ builder = Mockery::mock (Builder::class, [$ this ->queryBuilder ])->makePartial ();
57+ $ builder ->shouldAllowMockingProtectedMethods ();
58+ $ builder
59+ ->shouldReceive ('addUpdatedAtColumn ' )
60+ ->andReturn (['point ' => new Point (1 , 2 )]);
61+
62+ $ builder ->update (['point ' => new Point (1 , 3 )]);
63+ }
64+
65+ // public function testUpdateLinestring()
66+ // {
67+ // $this->queryBuilder
68+ // ->shouldReceive('raw')
69+ // ->with("ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')")
70+ // ->andReturn(new Expression("ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')"));
71+ //
72+ // $this->queryBuilder
73+ // ->shouldReceive('update')
74+ // ->andReturn(1);
75+ //
76+ // $linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]);
77+ //
78+ // $builder = Mockery::mock(Builder::class, [$this->queryBuilder])->makePartial();
79+ // $builder->shouldAllowMockingProtectedMethods();
80+ // $builder
81+ // ->shouldReceive('addUpdatedAtColumn')
82+ // ->andReturn(['linestring' => $linestring]);
83+ //
84+ // $builder
85+ // ->shouldReceive('asWKT')->with($linestring)->once();
86+ //
87+ // $builder->update(['linestring' => $linestring]);
88+ // }
89+ }
90+
91+ class TestBuilderModel extends Model
92+ {
93+ use SpatialTrait;
94+
95+ protected $ spatialFields = [
96+ 'point ' => Point::class,
97+ 'linestring ' => LineString::class,
98+ 'polygon ' => Polygon::class
99+ ];
100+ }
0 commit comments