disableEvents example

// Enable the statement execution end event and execute a query, both     // events captured.     $this->connection->enableEvents([StatementExecutionEndEvent::class]);
    $this->connection->query('SELECT * FROM {test}');
    $this->assertSame(2, $subscriber->countStatementStarts);
    $this->assertSame(1, $subscriber->countStatementEnds);
    $this->assertEmpty($subscriber->statementIdsInExecution);
    $this->assertTrue($this->connection->isEventEnabled(StatementExecutionStartEvent::class));
    $this->assertTrue($this->connection->isEventEnabled(StatementExecutionEndEvent::class));

    // Disable both events, no more events captured.     $this->connection->disableEvents([
      StatementExecutionStartEvent::class,
      StatementExecutionEndEvent::class,
    ]);
    $this->connection->query('SELECT * FROM {test}');
    $this->assertSame(2, $subscriber->countStatementStarts);
    $this->assertSame(1, $subscriber->countStatementEnds);
    $this->assertEmpty($subscriber->statementIdsInExecution);
    $this->assertFalse($this->connection->isEventEnabled(StatementExecutionStartEvent::class));
    $this->assertFalse($this->connection->isEventEnabled(StatementExecutionEndEvent::class));

    // Enable the statement execution end only, no events captured since the

  public function testEventEnablingAndDisabling(): void {
    $this->connection->enableEvents([
      StatementExecutionStartEvent::class,
      StatementExecutionEndEvent::class,
    ]);
    $this->assertTrue($this->connection->isEventEnabled(StatementExecutionStartEvent::class));
    $this->assertTrue($this->connection->isEventEnabled(StatementExecutionEndEvent::class));
    $this->connection->disableEvents([
      StatementExecutionEndEvent::class,
    ]);
    $this->assertTrue($this->connection->isEventEnabled(StatementExecutionStartEvent::class));
    $this->assertFalse($this->connection->isEventEnabled(StatementExecutionEndEvent::class));
  }

  /** * @covers ::enableEvents */
  public function testEnableInvalidEvent(): void {
    $this->expectException(\AssertionError::class);
    
Home | Imprint | This part of the site doesn't use cookies.