Skip to content

Commit

Permalink
PHPCS
Browse files Browse the repository at this point in the history
  • Loading branch information
puntope committed Jul 3, 2024
1 parent 2ad5d0e commit 1b92296
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/Jobs/Notifications/AbstractItemNotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected function process_items( array $args ): void {
__METHOD__

Check warning on line 48 in src/Jobs/Notifications/AbstractItemNotificationJob.php

View check run for this annotation

Codecov / codecov/patch

src/Jobs/Notifications/AbstractItemNotificationJob.php#L44-L48

Added lines #L44 - L48 were not covered by tests
);
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Product/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function is_ready_to_notify( WC_Product $product ): bool {
in_array( $product->get_type(), ProductSyncer::get_supported_product_types(), true );

if ( $is_ready && $product instanceof WC_Product_Variation ) {
$parent = $this->maybe_swap_for_parent( $product );
$parent = $this->maybe_swap_for_parent( $product );
$is_ready = $this->is_ready_to_notify( $parent );
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Jobs/ProductNotificationJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ public function create_item() {
}

public function test_sends_offer_id_on_delete() {
$item = $this->create_item();
$id = $item->get_id();
$topic = $this->get_topic_name() . '.delete';
$item = $this->create_item();
$id = $item->get_id();
$topic = $this->get_topic_name() . '.delete';

$this->job->get_helper()->expects( $this->once() )
->method( 'should_trigger_delete_notification' )
->willReturn( true );

$this->job->get_helper()->expects( $this->once() )
->method( 'get_offer_id' )
->willReturn( "gla_{$id}" );
->method( 'get_offer_id' )
->willReturn( "gla_{$id}" );

$this->notification_service->expects( $this->once() )->method( 'notify' )->with(
$topic,
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Product/ProductHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,10 @@ public function test_should_trigger_delete_notification() {


public function test_get_offer_id() {
$this->assertEquals( $this->product_helper->get_offer_id( 1 ), "gla_1" );
$this->assertEquals( $this->product_helper->get_offer_id( 1 ), 'gla_1' );
}

public function test_get_filtered_offer_id() {

add_filter(
'woocommerce_gla_get_google_product_offer_id',
function ( $value, $product_id ) {
Expand All @@ -1205,7 +1204,7 @@ function ( $value, $product_id ) {
2
);

$this->assertEquals( $this->product_helper->get_offer_id( 1 ), "custom_1" );
$this->assertEquals( $this->product_helper->get_offer_id( 1 ), 'custom_1' );

remove_filter(
'woocommerce_gla_get_google_product_offer_id',
Expand Down
83 changes: 43 additions & 40 deletions tests/Unit/Product/SyncerHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,18 +431,19 @@ public function test_unshow_unsynced_created_product_triggers_notification_delet
public function test_create_variable_product_triggers_notifications_for_variable_and_variations() {
$this->set_mc_and_notifications( true, true );
$variable_product = $this->create_variation_product();
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly(count($ids));
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly( count( $ids ) );
$this->product_notification_job->expects( $matcher )
->method( 'schedule' )
->with(
$this->callback( function($args) use ($ids, $matcher) {
$this->assertEquals( $args['item_id'], $ids[$matcher->getInvocationCount() - 1] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_CREATED );
return true;
}
)
);
->method( 'schedule' )
->with(
$this->callback(
function ( $args ) use ( $ids, $matcher ) {
$this->assertEquals( $args['item_id'], $ids[ $matcher->getInvocationCount() - 1 ] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_CREATED );
return true;
}
)
);

$variable_product->set_status( 'publish' );
$variable_product->save();
Expand All @@ -451,24 +452,25 @@ public function test_create_variable_product_triggers_notifications_for_variable
public function test_update_variable_product_triggers_notifications_for_variable_and_variations() {
$this->set_mc_and_notifications( true, true );
$variable_product = $this->create_variation_product();
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly(count($ids));
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly( count( $ids ) );

// Set all the variations and the variables as Created
foreach ( $ids as $id ) {
$this->product_helper->set_notification_status( wc_get_product( $id ), NotificationStatus::NOTIFICATION_CREATED );
}

$this->product_notification_job->expects( $matcher )
->method( 'schedule' )
->with(
$this->callback( function($args) use ($ids, $matcher) {
$this->assertEquals( $args['item_id'], $ids[$matcher->getInvocationCount() - 1] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_DELETED );
return true;
}
)
);
->method( 'schedule' )
->with(
$this->callback(
function ( $args ) use ( $ids, $matcher ) {
$this->assertEquals( $args['item_id'], $ids[ $matcher->getInvocationCount() - 1 ] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_DELETED );
return true;
}
)
);

$variable_product->set_status( 'publish' );
// Set the parent variable as DONT_SYNC_AND_SHOW
Expand All @@ -479,24 +481,25 @@ public function test_update_variable_product_triggers_notifications_for_variable
public function test_unsync_variable_product_triggers_notifications_for_variable_and_variations() {
$this->set_mc_and_notifications( true, true );
$variable_product = $this->create_variation_product();
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly(count($ids));
$ids = array_merge( [ $variable_product->get_id() ], $variable_product->get_children() );
$matcher = $this->exactly( count( $ids ) );

// Set all the variations and the variables as Created
foreach ( $ids as $id ) {
$this->product_helper->set_notification_status( wc_get_product( $id ), NotificationStatus::NOTIFICATION_CREATED );
}

$this->product_notification_job->expects( $matcher )
->method( 'schedule' )
->with(
$this->callback( function($args) use ($ids, $matcher) {
$this->assertEquals( $args['item_id'], $ids[$matcher->getInvocationCount() - 1] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_UPDATED );
return true;
}
)
);
->method( 'schedule' )
->with(
$this->callback(
function ( $args ) use ( $ids, $matcher ) {
$this->assertEquals( $args['item_id'], $ids[ $matcher->getInvocationCount() - 1 ] );
$this->assertEquals( $args['topic'], NotificationsService::TOPIC_PRODUCT_UPDATED );
return true;
}
)
);

$variable_product->set_status( 'publish' );
$variable_product->save();
Expand All @@ -508,9 +511,9 @@ public function test_trash_created_product_calls_notify_directly() {
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
$this->product_helper->set_notification_status( $product, NotificationStatus::NOTIFICATION_CREATED );

$this->notification_service->expects( $this->exactly(1) )
->method( 'notify' )
->with( NotificationsService::TOPIC_PRODUCT_DELETED, $product->get_id(), [ 'offer_id' => "gla_{$product->get_id()}"] );
$this->notification_service->expects( $this->exactly( 1 ) )
->method( 'notify' )
->with( NotificationsService::TOPIC_PRODUCT_DELETED, $product->get_id(), [ 'offer_id' => "gla_{$product->get_id()}" ] );

$product->delete();
}
Expand All @@ -521,9 +524,9 @@ public function test_delete_created_product_calls_notify_directly() {
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
$this->product_helper->set_notification_status( $product, NotificationStatus::NOTIFICATION_CREATED );

$this->notification_service->expects( $this->exactly(1) )
->method( 'notify' )
->with( NotificationsService::TOPIC_PRODUCT_DELETED, $product->get_id(), [ 'offer_id' => "gla_{$product->get_id()}"] );
$this->notification_service->expects( $this->exactly( 1 ) )
->method( 'notify' )
->with( NotificationsService::TOPIC_PRODUCT_DELETED, $product->get_id(), [ 'offer_id' => "gla_{$product->get_id()}" ] );

$product->delete( true );
}
Expand All @@ -533,7 +536,7 @@ public function test_delete_non_created_product_not_calling_notify() {
/** @var \WC_Product $product */
$product = WC_Helper_Product::create_simple_product( true, [ 'status' => 'draft' ] );
$this->notification_service->expects( $this->never() )
->method( 'notify' );
->method( 'notify' );

$product->delete();
$product->delete( true );
Expand Down

0 comments on commit 1b92296

Please sign in to comment.