Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
379fcba8
Commit
379fcba8
authored
Dec 31, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #100
parent
dfa9ff2a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
10 deletions
+37
-10
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+12
-2
SchemaTest.php
tests/SchemaTest.php
+17
-0
bootstrap.php
tests/bootstrap.php
+8
-8
No files found.
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
379fcba8
...
...
@@ -78,11 +78,21 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint {
{
$columns
=
$this
->
fluent
(
$columns
);
foreach
(
$columns
as
$column
)
// Columns are passed as a default array
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
$this
->
collection
->
deleteIndex
(
$column
);
// Transform the columns to the required array format
$transform
=
array
();
foreach
(
$columns
as
$column
)
{
$transform
[
$column
]
=
1
;
}
$columns
=
$transform
;
}
$this
->
collection
->
deleteIndex
(
$columns
);
return
$this
;
}
...
...
tests/SchemaTest.php
View file @
379fcba8
...
...
@@ -34,6 +34,14 @@ class SchemaTest extends PHPUnit_Framework_TestCase {
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey'
);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey'
]);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
index
(
array
(
'mykey'
));
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'mykey'
);
$this
->
assertEquals
(
1
,
$index
[
'key'
][
'mykey'
]);
}
public
function
testUnique
()
...
...
@@ -57,6 +65,15 @@ class SchemaTest extends PHPUnit_Framework_TestCase {
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$this
->
assertEquals
(
null
,
$index
);
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
dropIndex
(
array
(
'uniquekey'
));
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$this
->
assertEquals
(
null
,
$index
);
}
public
function
testBackground
()
...
...
tests/bootstrap.php
View file @
379fcba8
...
...
@@ -9,8 +9,7 @@ use Illuminate\Container\Container;
use
Illuminate\Database\DatabaseManager
;
use
Illuminate\Database\Connectors\ConnectionFactory
;
use
Illuminate\Events\Dispatcher
;
use
Illuminate\Cache\ArrayStore
;
use
Illuminate\Cache\Repository
;
use
Illuminate\Cache\CacheManager
;
# Fake app class
class
App
extends
ArrayObject
{
...
...
@@ -20,12 +19,6 @@ class App extends ArrayObject {
# Fake app
$app
=
new
App
;
# Event dispatcher
$app
[
'events'
]
=
new
Dispatcher
;
# Cache driver
$app
[
'cache'
]
=
new
Repository
(
new
ArrayStore
);
# Load database configuration
$config
=
require
'config/database.php'
;
foreach
(
$config
as
$key
=>
$value
)
...
...
@@ -33,6 +26,13 @@ foreach ($config as $key => $value)
$app
[
'config'
][
"database.
$key
"
]
=
$value
;
}
# Event dispatcher
$app
[
'events'
]
=
new
Dispatcher
;
# Cache driver
$app
[
'config'
][
'cache.driver'
]
=
'array'
;
$app
[
'cache'
]
=
new
CacheManager
(
$app
);
# Initialize database manager
$app
[
'db.factory'
]
=
new
ConnectionFactory
(
new
Container
);
$app
[
'db'
]
=
new
DatabaseManager
(
$app
,
$app
[
'db.factory'
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment