Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): update phpstan/phpstan requirement from 0.12.81 to 0.12.99 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"marc-mabe/php-enum": "~3.0",
"mockery/mockery": "~1.2",
"phpstan/extension-installer": "1.1.0",
"phpstan/phpstan": "0.12.81",
"phpstan/phpstan": "0.12.99",
"phpstan/phpstan-deprecation-rules": "0.12.6",
"phpstan/phpstan-nette": "0.12.16",
"phpstan/phpstan-mockery": "0.12.13",
Expand Down
35 changes: 35 additions & 0 deletions tests/cases/integration/Repository/repository.persistence.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Nextras\Orm\Exception\NullValueException;
use NextrasTests\Orm\Author;
use NextrasTests\Orm\Book;
use NextrasTests\Orm\Publisher;
use NextrasTests\Orm\Tag;
use NextrasTests\Orm\TestCase;
use Tester\Assert;

Expand Down Expand Up @@ -115,6 +116,40 @@ class RepositoryPersistenceTest extends TestCase

}


public function testManyHasMany(): void
{
// create 10 tags
for ($id = 0; $id < 10; $id++) {
$tag = $this->e(Tag::class, [
'name' => (string) $id,
]);
$this->orm->tags->persistAndFlush($tag);
}

// assign all tags to publisher
$publisher = $this->e(Publisher::class, [
'tags' => $this->orm->tags->findAll()->fetchAll(),
]);
$this->orm->publishers->persistAndFlush($publisher);

// assign publisher and only one tag
$book = $this->e(Book::class, [
'publisher' => $publisher,
'tags' => [
$this->orm->tags->getBy([]),
],
]);

// so one tag in book
Assert::same(1, $book->tags->count());

$this->orm->books->persistAndFlush($book);

// after pesist, there is all tags, not just one!
Assert::same(1, $book->tags->count());
}

}


Expand Down
10 changes: 10 additions & 0 deletions tests/db/mssql-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,13 @@ CREATE TABLE logs
count int NOT NULL,
PRIMARY KEY (date)
);


CREATE TABLE publishers_x_tags
(
publisher_id int NOT NULL,
tag_id int NOT NULL,
PRIMARY KEY (publisher_id, tag_id),
CONSTRAINT publishers_x_tags_tag FOREIGN KEY (tag_id) REFERENCES tags (id),
CONSTRAINT publishers_x_tags_publisher FOREIGN KEY (publisher_id) REFERENCES publishers (publisher_id) ON DELETE CASCADE
);
10 changes: 10 additions & 0 deletions tests/db/mysql-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,13 @@ CREATE TABLE logs
count INT NOT NULL,
PRIMARY KEY (date)
);


CREATE TABLE publishers_x_tags
(
publisher_id int NOT NULL,
tag_id int NOT NULL,
PRIMARY KEY (publisher_id, tag_id),
CONSTRAINT publishers_x_tags_tag FOREIGN KEY (tag_id) REFERENCES tags (id),
CONSTRAINT publishers_x_tags_publisher FOREIGN KEY (publisher_id) REFERENCES publishers (publisher_id) ON DELETE CASCADE
);
10 changes: 10 additions & 0 deletions tests/db/pgsql-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,13 @@ CREATE TABLE "logs"
"count" int NOT NULL,
PRIMARY KEY ("date")
);


CREATE TABLE "publishers_x_tags"
(
"publisher_id" int NOT NULL,
"tag_id" int NOT NULL,
PRIMARY KEY ("publisher_id", "tag_id"),
CONSTRAINT "publishers_x_tags_tag" FOREIGN KEY ("tag_id") REFERENCES "tags" ("id"),
CONSTRAINT "publishers_x_tags_publisher" FOREIGN KEY ("publisher_id") REFERENCES "publishers" ("publisher_id") ON DELETE CASCADE ON UPDATE CASCADE
);
2 changes: 2 additions & 0 deletions tests/inc/model/publisher/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Nextras\Orm\Entity\Entity;
use Nextras\Orm\Relationships\ManyHasMany as MHM;
use Nextras\Orm\Relationships\OneHasMany as OHM;


Expand All @@ -12,6 +13,7 @@
* @property int|null $publisherId {primary}
* @property string $name
* @property OHM|Book[] $books {1:m Book::$publisher}
* @property MHM|Tag[] $tags {m:m Tag::$publishers, isMain=true}
*/
final class Publisher extends Entity
{
Expand Down
1 change: 1 addition & 0 deletions tests/inc/model/tag/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property-read int|null $id {primary}
* @property-read string $name
* @property-read ICollection|Book[] $books {m:m Book::$tags, exposeCollection=true}
* @property-read ICollection|Publisher[] $publishers {m:m Publisher::$tags, exposeCollection=true}
* @property-read ICollection|TagFollower[] $tagFollowers {1:m TagFollower::$tag, cascade=[persist, remove], exposeCollection=true}
* @property-read bool $isGlobal {default true}
*/
Expand Down