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

Fix tests #22

Open
wants to merge 8 commits into
base: 0.1
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
1,066 changes: 752 additions & 314 deletions composer.lock

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
version: "3"

services:

#php server
php:
image: mctekk/phalconphp:7.4-debian
volumes:
- .:/app
- ./storage/ci/php.ini:/usr/local/etc/php/php.ini
depends_on:
- 'redis'
- 'mysql'
tty: true
ports:
- "9000:9000"
networks:
- local-network

redis:
image: 'redis:5.0-alpine'
ports:
- "6379:6379"
volumes:
- 'redis:/data'
networks:
- local-network

memcached:
image: memcached
ports:
- "11211:11211"
networks:
- local-network

elasticsearch: # Elasticsearch Instance
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
container_name: memo_elasticsearch
volumes: # Persist ES data in separate "esdata" volume
- esdata:/usr/share/elasticsearch/data
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
#command: ./bin/elasticsearch-plugin install https://d3g5vo6xdbdb9a.cloudfront.net/downloads/elasticsearch-plugins/opendistro-sql/opendistro_sql-1.6.0.0.zip #install opendistro sql plugin
#command: ./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/7.5.1.0/elasticsearch-sql-7.5.1.0.zip #install sql plugin
ports: # Expose Elasticsearch ports
- "9300:9300"
- "9200:9200"
networks:
- local-network

mysql:
image: mariadb:10.4
restart: always
ports:
- "3306:3306"
env_file:
- '.env'
volumes:
- "db-data:/var/lib/mysql"
networks:
- local-network
phpmyadmin:
depends_on:
- mysql
image: 'phpmyadmin/phpmyadmin:4.6'
ports:
- "9010:80"
environment:
- PMA_HOST=mysql
- MYSQL_ROOT_PASSWORD=nosenose
restart: always
networks:
- local-network
- public-network
rabbitmq:
image: rabbitmq:3.7
hostname: "rabbit"
env_file:
- '.env'
labels:
NAME: "rabbitmq1"
volumes:
- "rabbit:/var/lib/rabbitmq"
ports:
- "15672:15672"
- "5672:5672"
networks:
- local-network

beanstalkd:
image: schickling/beanstalkd:latest
restart: always
ports:
- "11300:11300"
networks:
- local-network

volumes:
db-data:
redis:
esdata:
rabbit:

networks:
local-network:
public-network:
37 changes: 37 additions & 0 deletions kanvas-phinx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use function Baka\appPath;
use Dotenv\Dotenv;

$dotenv = Dotenv::createImmutable(appPath());
$dotenv->load();

return [
'paths' => [
'migrations' => getenv('CANVAS_PHINX_CONFIG_DIR') . '/db/migrations',
'seeds' => getenv('CANVAS_PHINX_CONFIG_DIR') . '/db/seeds',
],
'environments' => [
'default_migration_table' => 'ut_migrations',
'default_database' => 'development',
'production' => [
'adapter' => 'mysql',
'host' => getenv('DATA_API_MYSQL_HOST'),
'name' => getenv('DATA_API_MYSQL_NAME'),
'user' => getenv('DATA_API_MYSQL_USER'),
'pass' => getenv('DATA_API_MYSQL_PASS'),
'port' => 3306,
'charset' => 'utf8',
],
'development' => [
'adapter' => 'mysql',
'host' => getenv('DATA_API_MYSQL_HOST'),
'name' => getenv('DATA_API_MYSQL_NAME'),
'user' => getenv('DATA_API_MYSQL_USER'),
'pass' => getenv('DATA_API_MYSQL_PASS'),
'port' => 3306,
'charset' => 'utf8',
],
],
'version_order' => 'creation',
];
2 changes: 1 addition & 1 deletion src/Comments/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function reply(string $message, UserInterface $user) : self
$comment->companies_id = $this->companies_id;
$comment->users_id = $user->getId();
$comment->message = $message;
$comment->parent_id = $this->getParentId();
$comment->parent_id = $this->id;
$comment->saveOrFail();

return $comment;
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Interactions/UsersInteractionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait UsersInteractionsTrait
*/
public function interact(ModelInterface $entity, string $interactionName) : bool
{
return SocialInteractions::add($this, $entity, $interactionName);
return (bool)!SocialInteractions::add($this, $entity, $interactionName)->is_deleted;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions storage/ci/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = -1
upload_max_filesize = 2048M
post_max_size = 2048M
20 changes: 20 additions & 0 deletions tests/_support/Models/Lead.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Kanvas\Social\Test\Support\Models;

use Kanvas\Social\Contracts\Channels\ChannelsInterface;
use Kanvas\Social\Contracts\Channels\ChannelsTrait;

class Lead extends BaseModel implements ChannelsInterface
{
use ChannelsTrait;

public int $id = 1;

public function getId() : int
{
return $this->id;
}
}
11 changes: 11 additions & 0 deletions tests/_support/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ public function getId() : int
{
return $this->id;
}

/**
* initialize.
*
* @return void
*/
public function initialize()
{
parent::initialize();
$this->setSource('tags');
}
}
59 changes: 32 additions & 27 deletions tests/integration/Services/CommentsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kanvas\Social\Tests\Integration\Social\Service;

use Baka\Support\Random;
use Canvas\Models\SystemModules;
use IntegrationTester;
use Kanvas\Social\Comments;
Expand All @@ -11,22 +12,15 @@
use Kanvas\Social\MessageTypes;
use Kanvas\Social\Models\MessageComments;
use Kanvas\Social\Models\Messages;
use Kanvas\Social\Models\UsersInteractions;
use Kanvas\Social\Models\UsersReactions;
use Kanvas\Social\Reactions;
use Kanvas\Social\Test\Support\Models\Users;

class CommentsCest
{
public MessageComments $comment;

/**
* Get the first comment.
*
* @return void
*/
protected function getCommentData() : void
{
$this->comment = MessageComments::findFirst('is_deleted = 0');
}

/**
* Test add comment.
Expand Down Expand Up @@ -63,15 +57,15 @@ public function addComment(IntegrationTester $I) : void
//Create a new Message for the comment
$feed = MessagesService::create($user, 'comments', $text);
$comment = Comments::add($feed->getId(), 'test-text', $user);

$this->comment = $comment;
$I->assertEquals('test-text', $comment->message);
}

/**
* Test comment edit.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
Expand All @@ -86,7 +80,7 @@ public function editComment(IntegrationTester $I) : void
* Test get Comment.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
Expand All @@ -101,23 +95,30 @@ public function getComment(IntegrationTester $I) : void
* Test reply comment.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
public function replyComment(IntegrationTester $I) : void
{
$reply = Comments::reply($this->comment->getId(), 'reply-test');
$commentReply = Random::generateDisplayName('reply-test', 100000);
codecept_debug($this->comment->id);
$reply = Comments::reply(
$this->comment->getId(),
$commentReply,
Users::findFirst(-1)
);
codecept_debug($reply->parent_id);

$I->assertEquals($reply->message, 'reply-test');
$I->assertEquals($reply->message, $commentReply);
$I->assertEquals($reply->parent_id, $this->comment->getId());
}

/**
* Test edit comment.
*
* @param IntegrationTester $I
* @before getCommentData
* @after getCommentsFromMessage
*
* @return void
*/
Expand All @@ -135,42 +136,46 @@ public function deleteComment(IntegrationTester $I) : void
* Test comments Reactions.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
public function commentReaction(IntegrationTester $I) : void
{
$user = Users::findFirst(1);
$I->assertFalse(Reactions::addMessageReaction('confuse', $user, $this->comment));
$I->assertFalse(Reactions::addMessageReaction('☺', $user, $this->comment));

$I->assertTrue(Reactions::addMessageReaction('confuse', $user, $this->comment));
$I->assertTrue(Reactions::addMessageReaction('☺', $user, $this->comment));
$reactionName = Random::generateDisplayName('confused', 2000);
Reactions::createReaction($reactionName, $user, '☺');
$reaction = Reactions::addMessageReaction($reactionName, $user, $this->comment);
$I->assertTrue($reaction instanceof UsersReactions);
$I->assertFalse((bool)$reaction->is_deleted);

$reaction = Reactions::addMessageReaction($reactionName, $user, $this->comment);
$I->assertTrue($reaction instanceof UsersReactions);
$I->assertTrue((bool)$reaction->is_deleted);
}

/**
* Test Users Comments Interaction.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
public function messageInteraction(IntegrationTester $I) : void
{
$user = Users::findFirst(1);
$user = Users::findFirst(-1);

$I->assertFalse(
Interactions::add($user, $this->comment, EnumsInteractions::REACT)
$I->assertTrue(
Interactions::add($user, $this->comment, EnumsInteractions::REACT) instanceof UsersInteractions
);
}

/**
* Test method to get comments from a message.
*
* @param IntegrationTester $I
* @before getCommentData
* after addComment
*
* @return void
*/
Expand Down
Loading