Skip to content

Commit 713f057

Browse files
committed
Schema::dropIfExists fixed and general tests created
1 parent f0ddbc6 commit 713f057

File tree

9 files changed

+110
-13
lines changed

9 files changed

+110
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ composer.lock
55

66
phpunit.xml
77
.env.testing
8+
/.phpunit.cache/test-results
9+
/.phpunit.result.cache

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"ext-pdo": "*"
2828
},
2929
"require-dev": {
30-
"orchestra/testbench": "^8.5"
30+
"orchestra/testbench": "^8.5",
31+
"nunomaduro/collision": "^7.4"
3132
},
3233
"extra": {
3334
"laravel": {

src/Database/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Exception;
88
use Illuminate\Database\Connection as IlluminateConnection;
99
use Illuminate\Database\Grammar;
10-
use Illuminate\Database\Query\Builder;
10+
use Illuminate\Database\Schema\Builder;
1111
use PDO;
1212
use Throwable;
1313
use Uepg\LaravelSybase\Database\Query\Grammar as QueryGrammar;

src/Database/Query/Grammar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Grammar extends IlluminateGrammar
99
{
1010
/**
11-
* All of the available clause operators.
11+
* All the available clause operators.
1212
*
1313
* @var array
1414
*/

src/Database/Schema/Grammar.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Uepg\LaravelSybase\Database\Schema;
44

55
use Illuminate\Database\Schema\Grammars\Grammar as IlluminateGrammar;
6-
use Uepg\LaravelSybase\Support\Fluent;
6+
use Illuminate\Support\Fluent;
77

88
class Grammar extends IlluminateGrammar
99
{
@@ -193,9 +193,11 @@ public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
193193
SELECT
194194
*
195195
FROM
196-
INFORMATION_SCHEMA.TABLES
196+
sysobjects
197197
WHERE
198-
TABLE_NAME = '" . $blueprint->getTable() . "'
198+
type = 'U'
199+
AND
200+
name = '" . $blueprint->getTable() . "'
199201
) DROP TABLE " . $blueprint->getTable();
200202
}
201203

testbench

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /usr/bin/env php
2+
<?php
3+
require __DIR__.'/vendor/bin/testbench';
4+
?>

tests/ExampleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Illuminate\Support\Facades\DB;
6+
7+
class ExampleTest extends TestCase
8+
{
9+
10+
public function testExample()
11+
{
12+
$db = DB::getDefaultConnection();
13+
$this->assertEquals(config('database.default'), $db);
14+
}
15+
}

tests/GeneralTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
use Uepg\LaravelSybase\Database\Schema\Blueprint;
8+
9+
class GeneralTest extends TestCase
10+
{
11+
12+
public function test_if_table_is_corrrectly_created()
13+
{
14+
if(!Schema::hasTable('test123')) {
15+
Schema::create('test123', function (Blueprint $table) {
16+
$table->increments('id');
17+
$table->string('test');
18+
});
19+
}
20+
21+
$this->assertTrue(Schema::hasTable('test123'));
22+
}
23+
24+
public function test_if_table_is_correctly_inserted()
25+
{
26+
$this->assertDatabaseCount('test123', 0);
27+
28+
DB::table('test123')->insert([
29+
'test' => 'test',
30+
]);
31+
$this->assertDatabaseCount('test123', 1);
32+
}
33+
34+
public function test_if_table_register_is_correctly_deleted()
35+
{
36+
$this->assertDatabaseCount('test123', 1);
37+
38+
DB::table('test123')->delete(1);
39+
40+
$this->assertDatabaseCount('test123', 0);
41+
}
42+
43+
public function test_if_table_is_correctly_dropped()
44+
{
45+
Schema::dropIfExists('test123');
46+
$this->assertNotTrue(Schema::hasTable('test123'));
47+
}
48+
}

tests/TestCase.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
namespace Tests;
44

5+
use Illuminate\Config\Repository;
56
use Illuminate\Foundation\Application;
67
use Illuminate\Support\ServiceProvider;
78

89
class TestCase extends \Orchestra\Testbench\TestCase
910
{
11+
/**
12+
* Ignore package discovery from.
13+
*
14+
* @return array<int, string>
15+
*/
16+
public function ignorePackageDiscoveriesFrom()
17+
{
18+
return [];
19+
}
20+
1021
/**
1122
* Get package providers.
1223
*
@@ -16,18 +27,32 @@ class TestCase extends \Orchestra\Testbench\TestCase
1627
*/
1728
protected function getPackageProviders($app)
1829
{
19-
return ['SybaseServiceProvider',];
30+
return ['Uepg\LaravelSybase\SybaseServiceProvider',];
2031
}
2132

2233
/**
23-
* Ignore package discovery from.
34+
* Define environment setup.
2435
*
25-
* @return array<int, string>
36+
* @param Application $app
37+
* @return void
2638
*/
27-
public function ignorePackageDiscoveriesFrom()
39+
protected function defineEnvironment($app)
2840
{
29-
return [];
30-
}
31-
41+
tap($app->make('config'), function (Repository $config) {
3242

43+
$config->set('database.default', 'sybase');
44+
$config->set('database.connections.sybase', [
45+
'driver' => 'sqlsrv',
46+
'host' => env('DB_HOST', 'localhost'),
47+
'port' => env('DB_PORT', '1433'),
48+
'database' => env('DB_DATABASE', 'forge'),
49+
'username' => env('DB_USERNAME', 'forge'),
50+
'password' => env('DB_PASSWORD', ''),
51+
'charset' => 'utf8',
52+
'prefix' => '',
53+
'prefix_indexes' => true,
54+
'options' => array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION)
55+
]);
56+
});
57+
}
3358
}

0 commit comments

Comments
 (0)