Skip to content

Commit

Permalink
ClrEvent test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed May 6, 2024
1 parent 232f292 commit 9df0cb0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Tests/Peachpie.Runtime.Tests/ClrFeaturesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,37 @@ class C {
Assert.AreEqual("Hello", (string)c_type.GetProperty("StringOnly").GetValue(c));
}
}

class ClrEventTestClass
{
public event EventHandler e;
public void fire() => e?.Invoke(this, EventArgs.Empty);
}

[TestMethod]
public void ClrEvent()
{
using (var ctx = Context.CreateEmpty())
{
// $x = new ClrEventTestClass;
ctx.Globals["x"] = PhpValue.FromClass(
new ClrEventTestClass()
);

var output = CompileAndRun(ctx, @"<?php
$hook = $x->e->add(
function ($sender, $args) {
echo '1';
}
);
$x->fire(); // invoke event
$hook->close(); // unsubscribe callable
$x->fire(); // invoke empty event
");
Assert.AreEqual("1", output);
}
}
}
}

0 comments on commit 9df0cb0

Please sign in to comment.