From dd369fbf40ff4fd642c661441f0a025ecc270fc7 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sat, 8 Feb 2020 05:31:42 +0300 Subject: [PATCH 1/4] Fix truncate on models According to docs array or object might be returned, so we need to add options. See https://docs.mongodb.com/php-library/v1.5/reference/method/MongoDBCollection-drop/ --- src/Jenssegers/Mongodb/Query/Builder.php | 6 +++++- tests/QueryBuilderTest.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Jenssegers/Mongodb/Query/Builder.php b/src/Jenssegers/Mongodb/Query/Builder.php index 558edbdf3..b2e1daf33 100644 --- a/src/Jenssegers/Mongodb/Query/Builder.php +++ b/src/Jenssegers/Mongodb/Query/Builder.php @@ -700,7 +700,11 @@ public function from($collection, $as = null) */ public function truncate() { - $result = $this->collection->drop(); + $options = [ + 'typeMap' => ['root' => 'object', 'document' => 'object'], + ]; + + $result = $this->collection->drop($options); return (1 == (int) $result->ok); } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 625e59cad..3306ede29 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -175,7 +175,8 @@ public function testDelete() public function testTruncate() { DB::collection('users')->insert(['name' => 'John Doe']); - DB::collection('users')->truncate(); + $result = DB::collection('users')->truncate(); + $this->assertEquals(1, $result); $this->assertEquals(0, DB::collection('users')->count()); } From ec4adb0e4b5de593e983ae09587ffd551aab8b82 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sat, 8 Feb 2020 05:36:56 +0300 Subject: [PATCH 2/4] Add tests for model truncate --- tests/ModelTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 108d28554..e998cade6 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -572,4 +572,13 @@ public function testChunkById(): void $this->assertEquals(3, $count); } + + public function testTruncateModel() + { + User::create(['name' => 'John Doe']); + + User::truncate(); + + $this->assertEquals(0, User::count()); + } } From 2d99506ca0cd94fb190215b57aa62d02abfbafab Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sat, 8 Feb 2020 13:45:14 +0100 Subject: [PATCH 3/4] [GF] Added issue template files --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 25 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/FEATURE-REQUEST.md | 18 ++++++++++++++++ .github/ISSUE_TEMPLATE/QUESTION.md | 8 ++++++++ 3 files changed, 51 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/BUG_REPORT.md create mode 100644 .github/ISSUE_TEMPLATE/FEATURE-REQUEST.md create mode 100644 .github/ISSUE_TEMPLATE/QUESTION.md diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md new file mode 100644 index 000000000..0f549303f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -0,0 +1,25 @@ +--- +name: "Bug report" +about: 'Report errors or unexpected behavior.' +--- + +- Laravel-mongodb Version: #.#.# +- PHP Version: #.#.# +- Database Driver & Version: + +### Description: + +### Steps to reproduce +1. +2. +3. + +### Expected behaviour +Tell us what should happen + +### Actual behaviour +Tell us what happens instead + +
Logs: +Insert log.txt here (if necessary) +
diff --git a/.github/ISSUE_TEMPLATE/FEATURE-REQUEST.md b/.github/ISSUE_TEMPLATE/FEATURE-REQUEST.md new file mode 100644 index 000000000..856dcd427 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/FEATURE-REQUEST.md @@ -0,0 +1,18 @@ +--- +name: Feature request +about: Suggest an idea. +title: "[Feature Request] " + +--- + +### Is your feature request related to a problem? +A clear and concise description of what the problem is. + +### Describe the solution you'd like +A clear and concise description of what you want to happen. + +### Describe alternatives you've considered +A clear and concise description of any alternative solutions or features you've considered. + +### Additional context +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/QUESTION.md b/.github/ISSUE_TEMPLATE/QUESTION.md new file mode 100644 index 000000000..ffd57814a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/QUESTION.md @@ -0,0 +1,8 @@ +--- +name: Question +about: Ask a question. +title: "[Question] " +labels: 'question' +assignees: '' + +--- From 37baf743524ec008c73beff278ff64a49ef5cc89 Mon Sep 17 00:00:00 2001 From: Michael Nardolillo Date: Sat, 8 Feb 2020 13:51:48 +0100 Subject: [PATCH 4/4] [GF] Add config for codacy --- .codacy.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .codacy.yml diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 000000000..59b32a797 --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,2 @@ +exclude_paths: + - '.github/**'